From ab883ea7777a9d8428a7a467d6fe6c5eae3ee77d Mon Sep 17 00:00:00 2001 From: James Grugett Date: Fri, 30 Sep 2022 12:00:14 -0500 Subject: [PATCH] Order home group sections by daily score. --- web/pages/home/edit.tsx | 16 ++----- web/pages/home/index.tsx | 93 ++++++++++++++++++++++------------------ 2 files changed, 56 insertions(+), 53 deletions(-) diff --git a/web/pages/home/edit.tsx b/web/pages/home/edit.tsx index 8c5f8ab5..0b496757 100644 --- a/web/pages/home/edit.tsx +++ b/web/pages/home/edit.tsx @@ -7,12 +7,11 @@ import { Row } from 'web/components/layout/row' import { Page } from 'web/components/page' import { SiteLink } from 'web/components/site-link' import { Title } from 'web/components/title' -import { useMemberGroupsSubscription } from 'web/hooks/use-group' import { useTracking } from 'web/hooks/use-tracking' import { useUser } from 'web/hooks/use-user' import { updateUser } from 'web/lib/firebase/users' import { track } from 'web/lib/service/analytics' -import { getHomeItems, TrendingGroupsSection } from '.' +import { getHomeItems } from '.' export default function Home() { const user = useUser() @@ -27,8 +26,7 @@ export default function Home() { setHomeSections(newHomeSections) } - const groups = useMemberGroupsSubscription(user) - const { sections } = getHomeItems(groups ?? [], homeSections) + const { sections } = getHomeItems(homeSections) return ( @@ -38,14 +36,8 @@ export default function Home() { - - - - - + + diff --git a/web/pages/home/index.tsx b/web/pages/home/index.tsx index e920b20f..de5e95f2 100644 --- a/web/pages/home/index.tsx +++ b/web/pages/home/index.tsx @@ -8,7 +8,7 @@ import { import { PlusCircleIcon, XCircleIcon } from '@heroicons/react/outline' import clsx from 'clsx' import { toast, Toaster } from 'react-hot-toast' -import { Dictionary } from 'lodash' +import { Dictionary, sortBy, sum } from 'lodash' import { Page } from 'web/components/page' import { Col } from 'web/components/layout/col' @@ -62,16 +62,16 @@ export default function Home() { } }) - const groups = useMemberGroupsSubscription(user) - - const { sections } = getHomeItems(groups ?? [], user?.homeSections ?? []) + const { sections } = getHomeItems(user?.homeSections ?? []) useEffect(() => { - if (user && !user.homeSections && sections.length > 0 && groups) { + if (user && !user.homeSections && sections.length > 0) { // Save initial home sections. updateUser(user.id, { homeSections: sections.map((s) => s.id) }) } - }, [user, sections, groups]) + }, [user, sections]) + + const groups = useMemberGroupsSubscription(user) const groupContracts = useContractsByDailyScoreGroups( groups?.map((g) => g.slug) @@ -94,14 +94,15 @@ export default function Home() { ) : ( <> - {sections.map((section) => - renderSection(section, user, groups, groupContracts) - )} + {sections.map((section) => renderSection(section, user))} + + {renderGroupSections(user, groups, groupContracts)} )} +