pronounsfu/frontend/pages/u/[user]/index.tsx

25 lines
671 B
TypeScript
Raw Normal View History

2022-08-16 18:04:06 -07:00
import { GetServerSideProps } from "next";
2022-12-22 06:49:08 -08:00
import PersonPage from "../../../components/PersonPage";
import { User } from "../../../lib/api";
import * as API from "../../../lib/api-fetch";
2022-08-16 18:04:06 -07:00
interface Props {
user: API.User;
2022-08-16 18:04:06 -07:00
}
export default function Index({ user }: Props) {
return <PersonPage person={new User(user)} />;
2022-08-16 18:04:06 -07:00
}
2022-11-20 07:04:53 -08:00
export const getServerSideProps: GetServerSideProps = async (context) => {
const userName = context.params!.user;
if (typeof userName !== "string") return { notFound: true };
2022-11-20 07:04:53 -08:00
try {
return { props: { user: await API.fetchAPI<User>(`/users/${userName}`) } };
2022-11-20 07:04:53 -08:00
} catch (e) {
console.log(e);
return { notFound: true };
}
};