Show user bets on their profile

This commit is contained in:
Austin Chen 2022-05-10 10:55:24 -04:00
parent 5adf430fad
commit 0dd0fe4578
2 changed files with 18 additions and 0 deletions

View File

@ -21,6 +21,9 @@ import { getContractFromId, listContracts } from 'web/lib/firebase/contracts'
import { LoadingIndicator } from './loading-indicator'
import { useRouter } from 'next/router'
import _ from 'lodash'
import { BetsList } from './bets-list'
import { Bet } from 'common/bet'
import { getUserBets } from 'web/lib/firebase/bets'
export function UserLink(props: {
name: string
@ -51,6 +54,7 @@ export function UserPage(props: {
const [usersContracts, setUsersContracts] = useState<Contract[] | 'loading'>(
'loading'
)
const [usersBets, setUsersBets] = useState<Bet[] | 'loading'>('loading')
const [commentsByContract, setCommentsByContract] = useState<
Map<Contract, Comment[]> | 'loading'
>('loading')
@ -59,6 +63,7 @@ export function UserPage(props: {
if (!user) return
getUsersComments(user.id).then(setUsersComments)
listContracts(user.id).then(setUsersContracts)
getUserBets(user.id).then(setUsersBets)
}, [user])
useEffect(() => {
@ -220,6 +225,13 @@ export function UserPage(props: {
<div className="px-0.5 font-bold">{usersComments.length}</div>
),
},
{
title: 'Bets',
content: <BetsList user={user} />,
tabIcon: (
<div className="px-0.5 font-bold">{usersBets.length}</div>
),
},
]}
/>
) : (

View File

@ -60,6 +60,12 @@ export function listenForBets(
})
}
export async function getUserBets(userId: string) {
return getValues<Bet>(
query(collectionGroup(db, 'bets'), where('userId', '==', userId))
)
}
export function listenForUserBets(
userId: string,
setBets: (bets: Bet[]) => void