From 1db24083cbc8c74487e09311a7d3bc2ab65d4303 Mon Sep 17 00:00:00 2001 From: DrMint Date: Sat, 2 Apr 2022 22:46:37 +0200 Subject: [PATCH] Added videos page and all --- src/components/Videos/VideoPreview.tsx | 2 +- src/graphql/operations/getVideo.graphql | 1 + .../operations/getVideoChannel.graphql | 36 ++++++ .../operations/getVideoChannelsSlugs.graphql | 9 ++ .../operations/getVideosPreview.graphql | 1 + src/pages/archives/videos/c/[uid].tsx | 107 ++++++++++++++++++ src/pages/archives/videos/index.tsx | 2 +- src/pages/archives/videos/{ => v}/[uid].tsx | 37 ++++-- 8 files changed, 182 insertions(+), 13 deletions(-) create mode 100644 src/graphql/operations/getVideoChannel.graphql create mode 100644 src/graphql/operations/getVideoChannelsSlugs.graphql create mode 100644 src/pages/archives/videos/c/[uid].tsx rename src/pages/archives/videos/{ => v}/[uid].tsx (82%) diff --git a/src/components/Videos/VideoPreview.tsx b/src/components/Videos/VideoPreview.tsx index efcde71..7311321 100644 --- a/src/components/Videos/VideoPreview.tsx +++ b/src/components/Videos/VideoPreview.tsx @@ -22,7 +22,7 @@ export default function PostPreview(props: Props): JSX.Element { const { video } = props; return ( - +
["data"][number]["attributes"]; +} + +export default function Channel(props: Props): JSX.Element { + const { langui, channel } = props; + const subPanel = ( + + + + + + ); + + const contentPanel = ( + +
+

{channel?.title}

+

{channel?.subscribers.toLocaleString()} subscribers

+
+
+ {channel?.videos?.data.map((video) => ( + <>{video.attributes && } + ))} +
+
+ ); + return ( + + ); +} + +export async function getStaticProps( + context: GetStaticPropsContext +): Promise<{ notFound: boolean } | { props: Props }> { + const sdk = getReadySdk(); + const channel = await sdk.getVideoChannel({ + channel: context.params?.uid?.toString() ?? "", + }); + if (!channel.videoChannels?.data[0].attributes) return { notFound: true }; + const props: Props = { + ...(await getAppStaticProps(context)), + channel: channel.videoChannels?.data[0].attributes, + }; + return { + props: props, + }; +} + +export async function getStaticPaths( + context: GetStaticPathsContext +): Promise { + const sdk = getReadySdk(); + const channels = await sdk.getVideoChannelsSlugs(); + const paths: GetStaticPathsResult["paths"] = []; + if (channels.videoChannels?.data) + channels.videoChannels.data.map((channel) => { + context.locales?.map((local) => { + if (channel.attributes) + paths.push({ + params: { uid: channel.attributes.uid }, + locale: local, + }); + }); + }); + return { + paths, + fallback: "blocking", + }; +} diff --git a/src/pages/archives/videos/index.tsx b/src/pages/archives/videos/index.tsx index ca1dfa0..56f24e8 100644 --- a/src/pages/archives/videos/index.tsx +++ b/src/pages/archives/videos/index.tsx @@ -39,7 +39,7 @@ export default function Videos(props: Props): JSX.Element { const contentPanel = ( -
+
{videos.map((video) => ( <>{video.attributes && } ))} diff --git a/src/pages/archives/videos/[uid].tsx b/src/pages/archives/videos/v/[uid].tsx similarity index 82% rename from src/pages/archives/videos/[uid].tsx rename to src/pages/archives/videos/v/[uid].tsx index 72c3d00..039e417 100644 --- a/src/pages/archives/videos/[uid].tsx +++ b/src/pages/archives/videos/v/[uid].tsx @@ -86,11 +86,23 @@ export default function Video(props: Props): JSX.Element { id="video" className="w-full rounded-xl shadow-shade shadow-lg overflow-hidden" > - + {video.gone ? ( + + ) : ( + + )} +

{video.title}

@@ -118,10 +130,13 @@ export default function Video(props: Props): JSX.Element { : video.likes.toLocaleString()}

)} - + + +
@@ -131,7 +146,7 @@ export default function Video(props: Props): JSX.Element {

{"Channel"}

- @@ -184,7 +199,7 @@ export async function getStaticPaths( context: GetStaticPathsContext ): Promise { const sdk = getReadySdk(); - const videos = await sdk.getVideo(); + const videos = await sdk.getVideosSlugs(); const paths: GetStaticPathsResult["paths"] = []; if (videos.videos?.data) videos.videos.data.map((video) => {