From a82b08796968058b27aa91b2109dcd94539f321f Mon Sep 17 00:00:00 2001 From: jeffvli Date: Thu, 12 Jan 2023 13:31:25 -0800 Subject: [PATCH] Add itemtype and optional pagination for carousel --- .../components/grid-carousel/index.tsx | 53 +++++++++++-------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/src/renderer/components/grid-carousel/index.tsx b/src/renderer/components/grid-carousel/index.tsx index fa774c5d..7edb2e4c 100644 --- a/src/renderer/components/grid-carousel/index.tsx +++ b/src/renderer/components/grid-carousel/index.tsx @@ -11,12 +11,14 @@ import styled from 'styled-components'; import { AlbumCard } from '/@/renderer/components/card'; import { usePlayQueueAdd } from '/@/renderer/features/player/hooks/use-playqueue-add'; import { LibraryItem } from '/@/renderer/api/types'; +import { usePlayButtonBehavior } from '/@/renderer/store/settings.store'; interface GridCarouselProps { cardRows: CardRow[]; children: React.ReactElement; containerWidth: number; data: any[] | undefined; + itemType: LibraryItem; loading?: boolean; pagination?: { handleNextPage?: () => void; @@ -78,9 +80,11 @@ const variants: Variants = { }; const Carousel = ({ data, cardRows }: any) => { - const { loading, pagination, gridHeight, imageSize, direction, uniqueId } = + const { loading, pagination, gridHeight, imageSize, direction, uniqueId, itemType } = useContext(GridCarouselContext); + const playButtonBehavior = usePlayButtonBehavior(); + const handlePlayQueueAdd = usePlayQueueAdd(); return ( @@ -105,9 +109,9 @@ const Carousel = ({ data, cardRows }: any) => { key={`card-${uniqueId}-${index}`} controls={{ cardRows, - itemType: LibraryItem.ALBUM, - playButtonBehavior: Play.NOW, - route: { + itemType: itemType || LibraryItem.ALBUM, + playButtonBehavior: playButtonBehavior || Play.NOW, + route: cardRows[0]?.route || { route: AppRoute.LIBRARY_ALBUMS_DETAIL, slugs: [{ idProperty: 'id', slugProperty: 'albumId' }], }, @@ -131,6 +135,7 @@ export const GridCarousel = ({ children, containerWidth, uniqueId, + itemType, }: GridCarouselProps) => { const [direction, setDirection] = useState(0); @@ -148,12 +153,13 @@ export const GridCarousel = ({ direction, gridHeight, imageSize, + itemType, loading, pagination, setDirection, uniqueId, }), - [cardRows, data, direction, gridHeight, imageSize, loading, pagination, uniqueId], + [cardRows, data, direction, gridHeight, imageSize, itemType, loading, pagination, uniqueId], ); return ( @@ -177,6 +183,7 @@ interface TitleProps { const Title = ({ children }: TitleProps) => { const { pagination, setDirection } = useContext(GridCarouselContext); + const showPaginationButtons = pagination?.handleNextPage && pagination?.handlePreviousPage; const handleNextPage = useCallback(() => { setDirection(1); @@ -191,23 +198,25 @@ const Title = ({ children }: TitleProps) => { return ( {children} - - - - + {showPaginationButtons && ( + + + + + )} ); };