manifold/web/pages/[username]/index.tsx

29 lines
795 B
TypeScript
Raw Normal View History

import { useRouter } from 'next/router'
import React, { useEffect, useState } from 'react'
2021-12-16 21:17:32 +00:00
import { getUserByUsername, User } from '../../lib/firebase/users'
2021-12-16 02:11:29 +00:00
import { UserPage } from '../../components/user-page'
2021-12-16 21:17:32 +00:00
import { useUser } from '../../hooks/use-user'
import Custom404 from '../404'
export default function UserProfile() {
const router = useRouter()
2021-12-16 21:17:32 +00:00
const [user, setUser] = useState<User | null | 'loading'>('loading')
2021-12-17 18:55:18 +00:00
const { username } = router.query as { username: string }
useEffect(() => {
if (username) {
getUserByUsername(username).then(setUser)
}
}, [username])
2021-12-16 21:17:32 +00:00
const currentUser = useUser()
if (user === 'loading') return <></>
return user ? (
2021-12-16 21:17:32 +00:00
<UserPage user={user} currentUser={currentUser || undefined} />
) : (
<Custom404 />
)
}