2022-04-12 19:18:16 +00:00
|
|
|
import type { GetServerSideProps, GetStaticProps, NextPage } from "next";
|
2022-03-29 17:19:24 +00:00
|
|
|
import { signIn, signOut, useSession } from "next-auth/react";
|
2022-04-12 19:18:16 +00:00
|
|
|
import { dehydrate, QueryClient } from "react-query";
|
2022-04-03 20:04:28 +00:00
|
|
|
import { CustomHead } from "../components/CustomHead";
|
2022-04-04 02:52:03 +00:00
|
|
|
import { Layout } from "../components/Layout";
|
|
|
|
import { VideoList } from "../components/VideoList";
|
2022-04-07 22:54:15 +00:00
|
|
|
import { getVideos } from "../lib/getVideos";
|
|
|
|
import { Videos } from "../types/video";
|
|
|
|
|
|
|
|
type HomeProps = {
|
|
|
|
videos: Videos;
|
|
|
|
imagePlaceholders?: string[];
|
|
|
|
};
|
2022-04-03 00:27:33 +00:00
|
|
|
|
|
|
|
const SignInOutButton = ({ isSignedIn }: { isSignedIn: boolean }) => {
|
|
|
|
if (isSignedIn) {
|
|
|
|
return <button onClick={() => signOut()}>Sign Out</button>;
|
|
|
|
}
|
|
|
|
return <button onClick={() => signIn()}>Sign in</button>;
|
|
|
|
};
|
2022-03-29 17:19:24 +00:00
|
|
|
|
2022-04-12 19:18:16 +00:00
|
|
|
const Home: NextPage<HomeProps> = () => {
|
2022-03-29 17:19:24 +00:00
|
|
|
const { data: session, status } = useSession();
|
2022-04-03 00:27:33 +00:00
|
|
|
const authData = {
|
|
|
|
session,
|
|
|
|
status,
|
|
|
|
};
|
|
|
|
|
2022-03-29 17:19:24 +00:00
|
|
|
return (
|
|
|
|
<>
|
2022-04-03 20:04:28 +00:00
|
|
|
<CustomHead />
|
2022-03-29 17:19:24 +00:00
|
|
|
|
2022-04-04 02:52:03 +00:00
|
|
|
<Layout>
|
2022-04-12 19:18:16 +00:00
|
|
|
<VideoList />
|
2022-04-03 00:27:33 +00:00
|
|
|
<SignInOutButton isSignedIn={!!session?.user} />
|
2022-04-04 02:52:03 +00:00
|
|
|
</Layout>
|
2022-03-29 17:19:24 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Home;
|
2022-04-04 02:52:03 +00:00
|
|
|
|
2022-04-07 22:54:15 +00:00
|
|
|
// http://localhost:8000/cache/videos/3/37Kn-kIsVu8.jpg
|
|
|
|
|
2022-04-12 19:18:16 +00:00
|
|
|
// export const getServerSideProps: GetServerSideProps = async (ctx) => {
|
|
|
|
// const videos = await getVideos();
|
2022-04-04 02:52:03 +00:00
|
|
|
|
2022-04-12 19:18:16 +00:00
|
|
|
// return { props: { videos } };
|
|
|
|
// };
|
|
|
|
|
|
|
|
export const getStaticProps: GetStaticProps = async () => {
|
|
|
|
const queryClient = new QueryClient();
|
|
|
|
|
|
|
|
await queryClient.prefetchQuery("videos", getVideos);
|
|
|
|
|
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
dehydratedState: dehydrate(queryClient),
|
|
|
|
},
|
|
|
|
};
|
2022-04-04 02:52:03 +00:00
|
|
|
};
|