import { AppLayout } from "components/AppLayout"; import { Icon } from "components/Ico"; import { PageSelector } from "components/Inputs/PageSelector"; import { Switch } from "components/Inputs/Switch"; import { PanelHeader } from "components/PanelComponents/PanelHeader"; import { ReturnButton, ReturnButtonType, } from "components/PanelComponents/ReturnButton"; import { ContentPanel, ContentPanelWidthSizes, } from "components/Panels/ContentPanel"; import { SubPanel } from "components/Panels/SubPanel"; import { PreviewCard } from "components/PreviewCard"; import { GetVideosPreviewQuery } from "graphql/generated"; import { AppStaticProps, getAppStaticProps } from "graphql/getAppStaticProps"; import { getReadySdk } from "graphql/sdk"; import { prettyDate } from "helpers/formatters"; import { getVideoThumbnailURL } from "helpers/videos"; import { GetStaticPropsContext } from "next"; import { Fragment, useState } from "react"; interface Props extends AppStaticProps { videos: NonNullable["data"]; } export default function Videos(props: Props): JSX.Element { const { langui, videos } = props; videos .sort((a, b) => { const dateA = a.attributes?.published_date ? prettyDate(a.attributes.published_date) : "9999"; const dateB = b.attributes?.published_date ? prettyDate(b.attributes.published_date) : "9999"; return dateA.localeCompare(dateB); }) .reverse(); const itemPerPage = 50; const paginatedVideos: Props["videos"][] = []; for (let index = 0; itemPerPage * index < videos.length; index += 1) { paginatedVideos.push( videos.slice(index * itemPerPage, (index + 1) * itemPerPage) ); } const [page, setPage] = useState(0); const [keepInfoVisible, setKeepInfoVisible] = useState(true); const subPanel = (

{langui.always_show_info}:

); const contentPanel = (
{paginatedVideos[page].map((video) => ( {video.attributes && ( )} ))}
); return ( ); } export async function getStaticProps( context: GetStaticPropsContext ): Promise<{ notFound: boolean } | { props: Props }> { const sdk = getReadySdk(); const videos = await sdk.getVideosPreview(); if (!videos.videos) return { notFound: true }; const props: Props = { ...(await getAppStaticProps(context)), videos: videos.videos.data, }; return { props: props, }; }