From ab6cfd25647ac72154df3018a917f0dd25da9790 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Sun, 6 Feb 2022 16:03:36 -0800 Subject: [PATCH] Show all recent activity if user has no folds --- web/pages/home.tsx | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/web/pages/home.tsx b/web/pages/home.tsx index f80c32b1..e3f32169 100644 --- a/web/pages/home.tsx +++ b/web/pages/home.tsx @@ -22,6 +22,7 @@ import { SearchIcon } from '@heroicons/react/outline' import { Row } from '../components/layout/row' import { SparklesIcon } from '@heroicons/react/solid' import { useFollowedFolds } from '../hooks/use-fold' +import { SiteLink } from '../components/site-link' export async function getStaticProps() { const [contracts, folds] = await Promise.all([ @@ -61,9 +62,9 @@ const Home = (props: { contracts.map((contract, index) => [contract.id, index]) ) - const followedFoldIds = useFollowedFolds(user) + const followedFoldIds = useFollowedFolds(user) ?? [] const followedFolds = filterDefined( - (followedFoldIds ?? []).map((id) => folds.find((fold) => fold.id === id)) + followedFoldIds.map((id) => folds.find((fold) => fold.id === id)) ) const tagSet = new Set( _.flatten(followedFolds.map((fold) => fold.lowercaseTags)) @@ -74,14 +75,16 @@ const Home = (props: { ? new Set(yourBetContractIds) : undefined - const feedContracts = - followedFoldIds && yourBetContracts - ? contracts.filter( - (contract) => - contract.lowercaseTags.some((tag) => tagSet.has(tag)) || - yourBetContracts.has(contract.id) - ) - : undefined + // By default, show all contracts + let feedContracts = contracts + // If the user is following any folds, then exclude all other contracts + if (yourBetContracts && followedFoldIds.length > 0) { + feedContracts = contracts.filter( + (contract) => + contract.lowercaseTags.some((tag) => tagSet.has(tag)) || + yourBetContracts.has(contract.id) + ) + } const oneDayMS = 24 * 60 * 60 * 1000 const recentBets = (feedContracts ?? []) @@ -142,7 +145,19 @@ const Home = (props: { + {activeContracts ? (