From a840143990b14c11a1d8cd18daf7d4f52743b308 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Tue, 31 May 2022 18:06:27 -0700 Subject: [PATCH] Publicly display bets without infinite looping React why --- web/components/bets-list.tsx | 13 +++++++++---- web/components/user-page.tsx | 28 +++++++++++++++++++++------- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/web/components/bets-list.tsx b/web/components/bets-list.tsx index 6508e2fb..ff5a31e1 100644 --- a/web/components/bets-list.tsx +++ b/web/components/bets-list.tsx @@ -54,9 +54,14 @@ import { SellSharesModal } from './sell-modal' type BetSort = 'newest' | 'profit' | 'closeTime' | 'value' type BetFilter = 'open' | 'sold' | 'closed' | 'resolved' | 'all' -export function BetsList(props: { user: User }) { - const { user } = props - const bets = useUserBets(user.id, { includeRedemptions: true }) +export function BetsList(props: { user: User; hideBetsBefore?: number }) { + const { user, hideBetsBefore } = props + const allBets = useUserBets(user.id, { includeRedemptions: true }) + // Hide bets before 06-01-2022 if this isn't your own profile + // NOTE: This means public profits also begin on 06-01-2022 as well. + const bets = (allBets ?? []).filter( + (bet) => bet.createdTime >= (hideBetsBefore ?? 0) + ) const [contracts, setContracts] = useState() const [sort, setSort] = useState('newest') @@ -77,7 +82,7 @@ export function BetsList(props: { user: User }) { disposed = true } } - }, [bets]) + }, [allBets]) const getTime = useTimeSinceFirstRender() useEffect(() => { diff --git a/web/components/user-page.tsx b/web/components/user-page.tsx index e1398fea..c1099ce8 100644 --- a/web/components/user-page.tsx +++ b/web/components/user-page.tsx @@ -44,6 +44,7 @@ export function UserLink(props: { } export const TAB_IDS = ['markets', 'comments', 'bets'] +const JUNE_1_2022 = new Date('2022-06-01T00:00:00.000Z').valueOf() export function UserPage(props: { user: User @@ -229,14 +230,27 @@ export function UserPage(props: { title: 'Bets', content: (
- + )} + - {isCurrentUser && } + {!isCurrentUser && ( + <> + + + + )}
), tabIcon: (