2021-12-16 00:52:19 +00:00
|
|
|
import { useRouter } from 'next/router'
|
2022-07-11 00:42:34 +00:00
|
|
|
import React 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'
|
2022-07-11 00:42:34 +00:00
|
|
|
import { fromPropz, usePropz } from 'web/hooks/use-propz'
|
|
|
|
|
|
|
|
export const getStaticProps = fromPropz(getStaticPropz)
|
|
|
|
export async function getStaticPropz(props: { params: { username: string } }) {
|
|
|
|
const { username } = props.params
|
|
|
|
const user = await getUserByUsername(username)
|
|
|
|
|
2022-08-09 03:29:10 +00:00
|
|
|
if (user) user.profitCached.allTime = 0
|
|
|
|
|
2022-07-11 00:42:34 +00:00
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
user,
|
|
|
|
},
|
|
|
|
|
|
|
|
revalidate: 60, // regenerate after a minute
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getStaticPaths() {
|
|
|
|
return { paths: [], fallback: 'blocking' }
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function UserProfile(props: { user: User | null }) {
|
|
|
|
props = usePropz(props, getStaticPropz) ?? { user: undefined }
|
|
|
|
const { user } = props
|
2021-12-16 00:52:19 +00:00
|
|
|
|
|
|
|
const router = useRouter()
|
2022-07-25 20:27:09 +00:00
|
|
|
const { username } = router.query as {
|
2022-06-22 16:35:50 +00:00
|
|
|
username: string
|
|
|
|
}
|
2021-12-16 21:17:32 +00:00
|
|
|
const currentUser = useUser()
|
|
|
|
|
2022-06-15 21:34:34 +00:00
|
|
|
useTracking('view user profile', { username })
|
|
|
|
|
2022-08-22 23:27:56 +00:00
|
|
|
if (user === undefined || user?.username !== username) return <div />
|
2021-12-16 05:56:03 +00:00
|
|
|
|
2021-12-16 01:34:36 +00:00
|
|
|
return user ? (
|
2022-07-25 20:27:09 +00:00
|
|
|
<UserPage user={user} currentUser={currentUser || undefined} />
|
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
|
|
|
)
|
|
|
|
}
|