2021-12-16 00:52:19 +00:00
|
|
|
import { useRouter } from 'next/router'
|
2021-12-16 01:34:36 +00:00
|
|
|
import React, { useEffect, useState } from 'react'
|
2021-12-16 21:17:32 +00:00
|
|
|
|
2022-05-09 13:04:36 +00:00
|
|
|
import { getUserByUsername, User } from 'web/lib/firebase/users'
|
|
|
|
import { UserPage } from 'web/components/user-page'
|
|
|
|
import { useUser } from 'web/hooks/use-user'
|
2022-01-16 03:09:15 +00:00
|
|
|
import Custom404 from '../404'
|
2022-06-15 21:34:34 +00:00
|
|
|
import { useTracking } from 'web/hooks/use-tracking'
|
2021-12-16 00:52:19 +00:00
|
|
|
|
2022-05-18 15:52:12 +00:00
|
|
|
export default function UserProfile(props: {
|
|
|
|
tab?: 'markets' | 'comments' | 'bets'
|
|
|
|
}) {
|
2021-12-16 00:52:19 +00:00
|
|
|
const router = useRouter()
|
2021-12-16 21:17:32 +00:00
|
|
|
const [user, setUser] = useState<User | null | 'loading'>('loading')
|
2022-05-18 15:52:12 +00:00
|
|
|
const { username } = router.query as { username: string }
|
2022-06-15 21:34:34 +00:00
|
|
|
|
2021-12-16 01:34:36 +00:00
|
|
|
useEffect(() => {
|
|
|
|
if (username) {
|
|
|
|
getUserByUsername(username).then(setUser)
|
|
|
|
}
|
|
|
|
}, [username])
|
2021-12-16 00:52:19 +00:00
|
|
|
|
2021-12-16 21:17:32 +00:00
|
|
|
const currentUser = useUser()
|
|
|
|
|
2022-06-15 21:34:34 +00:00
|
|
|
useTracking('view user profile', { username })
|
|
|
|
|
2021-12-16 05:56:03 +00:00
|
|
|
if (user === 'loading') return <></>
|
|
|
|
|
2021-12-16 01:34:36 +00:00
|
|
|
return user ? (
|
2022-05-05 22:30:30 +00:00
|
|
|
<UserPage
|
|
|
|
user={user}
|
|
|
|
currentUser={currentUser || undefined}
|
2022-05-18 15:52:12 +00:00
|
|
|
defaultTabTitle={props.tab}
|
2022-05-05 22:30:30 +00:00
|
|
|
/>
|
2021-12-16 01:34:36 +00:00
|
|
|
) : (
|
2022-01-16 03:09:15 +00:00
|
|
|
<Custom404 />
|
2021-12-16 00:52:19 +00:00
|
|
|
)
|
|
|
|
}
|