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'
|
|
|
|
import { getUserByUsername, User } from '../../lib/firebase/users'
|
2021-12-16 02:11:29 +00:00
|
|
|
import { UserPage } from '../../components/user-page'
|
2021-12-16 01:34:36 +00:00
|
|
|
import Error from 'next/error'
|
2021-12-16 00:52:19 +00:00
|
|
|
|
2021-12-16 01:34:36 +00:00
|
|
|
export default function UserProfile() {
|
2021-12-16 00:52:19 +00:00
|
|
|
const router = useRouter()
|
2021-12-16 01:34:36 +00:00
|
|
|
const [user, setUser] = useState<User | null>(null)
|
2021-12-16 00:52:19 +00:00
|
|
|
const { username } = router.query as { username: string }
|
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 01:34:36 +00:00
|
|
|
const errorMessage = `Who is this "${username}" you speak of..`
|
|
|
|
return user ? (
|
|
|
|
<UserPage user={user} />
|
|
|
|
) : (
|
|
|
|
<Error statusCode={404} title={errorMessage} />
|
2021-12-16 00:52:19 +00:00
|
|
|
)
|
|
|
|
}
|