Small home refactor
This commit is contained in:
parent
ca6197c7bb
commit
6a0b577aeb
|
@ -21,7 +21,6 @@ import { Group } from 'common/group'
|
||||||
import { SiteLink } from 'web/components/site-link'
|
import { SiteLink } from 'web/components/site-link'
|
||||||
import { usePrivateUser, useUser } from 'web/hooks/use-user'
|
import { usePrivateUser, useUser } from 'web/hooks/use-user'
|
||||||
import {
|
import {
|
||||||
useMemberGroupIds,
|
|
||||||
useMemberGroupsSubscription,
|
useMemberGroupsSubscription,
|
||||||
useTrendingGroups,
|
useTrendingGroups,
|
||||||
} from 'web/hooks/use-group'
|
} from 'web/hooks/use-group'
|
||||||
|
@ -80,6 +79,7 @@ export default function Home() {
|
||||||
const dailyTrendingContracts = useContractsByDailyScoreNotBetOn(user?.id, 6)
|
const dailyTrendingContracts = useContractsByDailyScoreNotBetOn(user?.id, 6)
|
||||||
|
|
||||||
const groups = useMemberGroupsSubscription(user)
|
const groups = useMemberGroupsSubscription(user)
|
||||||
|
const trendingGroups = useTrendingGroups()
|
||||||
const groupContracts = useContractsByDailyScoreGroups(
|
const groupContracts = useContractsByDailyScoreGroups(
|
||||||
groups?.map((g) => g.slug)
|
groups?.map((g) => g.slug)
|
||||||
)
|
)
|
||||||
|
@ -113,17 +113,27 @@ export default function Home() {
|
||||||
<LoadingIndicator />
|
<LoadingIndicator />
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
{renderSections(user, sections, {
|
{renderSections(sections, {
|
||||||
score: trendingContracts,
|
score: trendingContracts,
|
||||||
newest: newContracts,
|
newest: newContracts,
|
||||||
'daily-trending': dailyTrendingContracts,
|
'daily-trending': dailyTrendingContracts,
|
||||||
'daily-movers': dailyMovers,
|
'daily-movers': dailyMovers,
|
||||||
})}
|
})}
|
||||||
|
|
||||||
<TrendingGroupsSection user={user} />
|
{groups && groupContracts && trendingGroups.length > 0 ? (
|
||||||
|
<>
|
||||||
|
<TrendingGroupsSection
|
||||||
|
className="mb-4"
|
||||||
|
user={user}
|
||||||
|
myGroups={groups}
|
||||||
|
trendingGroups={trendingGroups}
|
||||||
|
/>
|
||||||
{renderGroupSections(user, groups, groupContracts)}
|
{renderGroupSections(user, groups, groupContracts)}
|
||||||
</>
|
</>
|
||||||
|
) : (
|
||||||
|
<LoadingIndicator />
|
||||||
|
)}
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
|
@ -171,7 +181,6 @@ export const getHomeItems = (sections: string[]) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderSections(
|
function renderSections(
|
||||||
user: User,
|
|
||||||
sections: { id: string; label: string }[],
|
sections: { id: string; label: string }[],
|
||||||
sectionContracts: {
|
sectionContracts: {
|
||||||
'daily-movers': CPMMBinaryContract[]
|
'daily-movers': CPMMBinaryContract[]
|
||||||
|
@ -192,7 +201,7 @@ function renderSections(
|
||||||
}
|
}
|
||||||
if (id === 'daily-trending') {
|
if (id === 'daily-trending') {
|
||||||
return (
|
return (
|
||||||
<ContractsSection
|
<SearchSection
|
||||||
key={id}
|
key={id}
|
||||||
label={label}
|
label={label}
|
||||||
contracts={contracts}
|
contracts={contracts}
|
||||||
|
@ -202,11 +211,11 @@ function renderSections(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<ContractsSection
|
<SearchSection
|
||||||
key={id}
|
key={id}
|
||||||
label={label}
|
label={label}
|
||||||
contracts={contracts}
|
contracts={contracts}
|
||||||
sort={id === 'daily-trending' ? 'daily-score' : (id as Sort)}
|
sort={id as Sort}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
|
@ -216,13 +225,9 @@ function renderSections(
|
||||||
|
|
||||||
function renderGroupSections(
|
function renderGroupSections(
|
||||||
user: User,
|
user: User,
|
||||||
groups: Group[] | undefined,
|
groups: Group[],
|
||||||
groupContracts: Dictionary<CPMMBinaryContract[]> | undefined
|
groupContracts: Dictionary<CPMMBinaryContract[]>
|
||||||
) {
|
) {
|
||||||
if (!groups || !groupContracts) {
|
|
||||||
return <LoadingIndicator />
|
|
||||||
}
|
|
||||||
|
|
||||||
const filteredGroups = groups.filter((g) => groupContracts[g.slug])
|
const filteredGroups = groups.filter((g) => groupContracts[g.slug])
|
||||||
const orderedGroups = sortBy(filteredGroups, (g) =>
|
const orderedGroups = sortBy(filteredGroups, (g) =>
|
||||||
// Sort by sum of top two daily scores.
|
// Sort by sum of top two daily scores.
|
||||||
|
@ -285,7 +290,7 @@ function SectionHeader(props: {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function ContractsSection(props: {
|
function SearchSection(props: {
|
||||||
label: string
|
label: string
|
||||||
contracts: CPMMBinaryContract[]
|
contracts: CPMMBinaryContract[]
|
||||||
sort: Sort
|
sort: Sort
|
||||||
|
@ -406,15 +411,16 @@ function DailyStats(props: {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function TrendingGroupsSection(props: {
|
export function TrendingGroupsSection(props: {
|
||||||
user: User | null | undefined
|
user: User
|
||||||
|
myGroups: Group[]
|
||||||
|
trendingGroups: Group[]
|
||||||
className?: string
|
className?: string
|
||||||
}) {
|
}) {
|
||||||
const { user, className } = props
|
const { user, myGroups, trendingGroups, className } = props
|
||||||
const memberGroupIds = useMemberGroupIds(user) || []
|
|
||||||
|
|
||||||
const groups = useTrendingGroups().filter(
|
const myGroupIds = new Set(myGroups.map((g) => g.id))
|
||||||
(g) => !memberGroupIds.includes(g.id)
|
|
||||||
)
|
const groups = trendingGroups.filter((g) => !myGroupIds.has(g.id))
|
||||||
const count = 20
|
const count = 20
|
||||||
const chosenGroups = groups.slice(0, count)
|
const chosenGroups = groups.slice(0, count)
|
||||||
|
|
||||||
|
@ -433,10 +439,9 @@ export function TrendingGroupsSection(props: {
|
||||||
<PillButton
|
<PillButton
|
||||||
className="flex flex-row items-center gap-1"
|
className="flex flex-row items-center gap-1"
|
||||||
key={g.id}
|
key={g.id}
|
||||||
selected={memberGroupIds.includes(g.id)}
|
selected={myGroupIds.has(g.id)}
|
||||||
onSelect={() => {
|
onSelect={() => {
|
||||||
if (!user) return
|
if (myGroupIds.has(g.id)) leaveGroup(g, user.id)
|
||||||
if (memberGroupIds.includes(g.id)) leaveGroup(g, user?.id)
|
|
||||||
else {
|
else {
|
||||||
const homeSections = (user.homeSections ?? [])
|
const homeSections = (user.homeSections ?? [])
|
||||||
.filter((id) => id !== g.id)
|
.filter((id) => id !== g.id)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user