64462d6ab4
* Make better tabs components, apply to user page * Remove fishy unused href property from tabs * Remove tab ID property * Clean up crufty markup in tabs component * Fix naming to be right (thanks James!)
49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import { useRouter } from 'next/router'
|
|
import React from 'react'
|
|
|
|
import { getUserByUsername, User } from 'web/lib/firebase/users'
|
|
import { UserPage } from 'web/components/user-page'
|
|
import { useUser } from 'web/hooks/use-user'
|
|
import Custom404 from '../404'
|
|
import { useTracking } from 'web/hooks/use-tracking'
|
|
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)
|
|
|
|
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
|
|
|
|
const router = useRouter()
|
|
const { username } = router.query as {
|
|
username: string
|
|
}
|
|
const currentUser = useUser()
|
|
|
|
useTracking('view user profile', { username })
|
|
|
|
if (user === undefined) return <div />
|
|
|
|
return user ? (
|
|
<UserPage user={user} currentUser={currentUser || undefined} />
|
|
) : (
|
|
<Custom404 />
|
|
)
|
|
}
|