diff --git a/front/src/components/horizontal-list.tsx b/front/src/components/horizontal-list.tsx new file mode 100644 index 00000000..4580b83d --- /dev/null +++ b/front/src/components/horizontal-list.tsx @@ -0,0 +1,77 @@ +/* + * Kyoo - A portable and vast media library solution. + * Copyright (c) Kyoo. + * + * See AUTHORS.md and LICENSE file in the project root for full license information. + * + * Kyoo is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * Kyoo is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Kyoo. If not, see . + */ + +import { ArrowLeft, ArrowRight } from "@mui/icons-material"; +import { Box, IconButton, Typography } from "@mui/material"; +import { ReactNode, useRef } from "react"; +import { Container } from "./container"; + +export const HorizontalList = ({ title, noContent, children }: { title: string, noContent: string, children: ReactNode[] }) => { + const ref = useRef(null); + const getScrollSize = () => { + const childSize = ref.current?.children[0].clientWidth; + const containerSize = ref.current?.offsetWidth; + + if (!childSize || !containerSize) return childSize || 150; + return Math.round(containerSize / childSize) * childSize; + }; + + // TODO: handle infinite scroll + + return ( + <> + + + {title} + + + ref.current?.scrollBy({ left: -getScrollSize(), behavior: "smooth" })}> + + + ref.current?.scrollBy({ left: getScrollSize(), behavior: "smooth" })}> + + + + + {children.length == 0 ? ( + + {noContent} + + ) : ( + + {children} + + )} + + ); +} diff --git a/front/src/pages/show/[slug].tsx b/front/src/pages/show/[slug].tsx index b7f0dd64..fa0932ee 100644 --- a/front/src/pages/show/[slug].tsx +++ b/front/src/pages/show/[slug].tsx @@ -18,9 +18,8 @@ * along with Kyoo. If not, see . */ -import { ArrowLeft, ArrowRight, LocalMovies, PlayArrow } from "@mui/icons-material"; +import { LocalMovies, PlayArrow } from "@mui/icons-material"; import { - alpha, Box, Divider, Fab, @@ -31,13 +30,12 @@ import { Tabs, Tooltip, Typography, - useTheme, } from "@mui/material"; import useTranslation from "next-translate/useTranslation"; import Head from "next/head"; import { Navbar } from "~/components/navbar"; import { Image, Poster } from "~/components/poster"; -import { Episode, EpisodeP, Page, Season, Show, ShowP } from "~/models"; +import { Episode, EpisodeP, Season, Show, ShowP } from "~/models"; import { QueryIdentifier, QueryPage, useFetch, useInfiniteFetch } from "~/utils/query"; import { getDisplayDate } from "~/models/utils"; import { withRoute } from "~/utils/router"; @@ -45,13 +43,14 @@ import { Container } from "~/components/container"; import { makeTitle } from "~/utils/utils"; import { Link } from "~/utils/link"; import { Studio } from "~/models/resources/studio"; -import { Paged, Person, PersonP } from "~/models"; +import { Person, PersonP } from "~/models"; import { PersonAvatar } from "~/components/person"; import { ErrorComponent, ErrorPage } from "~/components/errors"; import { useState } from "react"; import { EpisodeLine } from "~/components/episode"; import InfiniteScroll from "react-infinite-scroll-component"; import { useRouter } from "next/router"; +import { HorizontalList } from "~/components/horizontal-list"; const StudioText = ({ studio, @@ -261,7 +260,7 @@ const staffQuery = (slug: string): QueryIdentifier => ({ }); const ShowStaff = ({ slug }: { slug: string }) => { - const { data, isError, error, hasNextPage, fetchNextPage } = useInfiniteFetch(staffQuery(slug)); + const { data, isError, error } = useInfiniteFetch(staffQuery(slug)); const { t } = useTranslation("browse"); // TODO: handle infinite scroll @@ -269,48 +268,15 @@ const ShowStaff = ({ slug }: { slug: string }) => { if (isError) return ; return ( - <> - - - {t("show.staff")} - - - - - - - - - - - {data && data?.pages.at(0)?.count === 0 ? ( - - {t("show.staff-none")} - - ) : ( - - {(data ? data.pages.flatMap((x) => x.items) : [...Array(20)]).map((x, i) => ( - - ))} - - )} - + + {(data ? data.pages.flatMap((x) => x.items) : [...Array(20)]).map((x, i) => ( + + ))} + ); };