Add itemtype and optional pagination for carousel
This commit is contained in:
parent
45aef104fe
commit
a82b087969
1 changed files with 31 additions and 22 deletions
|
@ -11,12 +11,14 @@ import styled from 'styled-components';
|
||||||
import { AlbumCard } from '/@/renderer/components/card';
|
import { AlbumCard } from '/@/renderer/components/card';
|
||||||
import { usePlayQueueAdd } from '/@/renderer/features/player/hooks/use-playqueue-add';
|
import { usePlayQueueAdd } from '/@/renderer/features/player/hooks/use-playqueue-add';
|
||||||
import { LibraryItem } from '/@/renderer/api/types';
|
import { LibraryItem } from '/@/renderer/api/types';
|
||||||
|
import { usePlayButtonBehavior } from '/@/renderer/store/settings.store';
|
||||||
|
|
||||||
interface GridCarouselProps {
|
interface GridCarouselProps {
|
||||||
cardRows: CardRow<any>[];
|
cardRows: CardRow<any>[];
|
||||||
children: React.ReactElement;
|
children: React.ReactElement;
|
||||||
containerWidth: number;
|
containerWidth: number;
|
||||||
data: any[] | undefined;
|
data: any[] | undefined;
|
||||||
|
itemType: LibraryItem;
|
||||||
loading?: boolean;
|
loading?: boolean;
|
||||||
pagination?: {
|
pagination?: {
|
||||||
handleNextPage?: () => void;
|
handleNextPage?: () => void;
|
||||||
|
@ -78,9 +80,11 @@ const variants: Variants = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const Carousel = ({ data, cardRows }: any) => {
|
const Carousel = ({ data, cardRows }: any) => {
|
||||||
const { loading, pagination, gridHeight, imageSize, direction, uniqueId } =
|
const { loading, pagination, gridHeight, imageSize, direction, uniqueId, itemType } =
|
||||||
useContext(GridCarouselContext);
|
useContext(GridCarouselContext);
|
||||||
|
|
||||||
|
const playButtonBehavior = usePlayButtonBehavior();
|
||||||
|
|
||||||
const handlePlayQueueAdd = usePlayQueueAdd();
|
const handlePlayQueueAdd = usePlayQueueAdd();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -105,9 +109,9 @@ const Carousel = ({ data, cardRows }: any) => {
|
||||||
key={`card-${uniqueId}-${index}`}
|
key={`card-${uniqueId}-${index}`}
|
||||||
controls={{
|
controls={{
|
||||||
cardRows,
|
cardRows,
|
||||||
itemType: LibraryItem.ALBUM,
|
itemType: itemType || LibraryItem.ALBUM,
|
||||||
playButtonBehavior: Play.NOW,
|
playButtonBehavior: playButtonBehavior || Play.NOW,
|
||||||
route: {
|
route: cardRows[0]?.route || {
|
||||||
route: AppRoute.LIBRARY_ALBUMS_DETAIL,
|
route: AppRoute.LIBRARY_ALBUMS_DETAIL,
|
||||||
slugs: [{ idProperty: 'id', slugProperty: 'albumId' }],
|
slugs: [{ idProperty: 'id', slugProperty: 'albumId' }],
|
||||||
},
|
},
|
||||||
|
@ -131,6 +135,7 @@ export const GridCarousel = ({
|
||||||
children,
|
children,
|
||||||
containerWidth,
|
containerWidth,
|
||||||
uniqueId,
|
uniqueId,
|
||||||
|
itemType,
|
||||||
}: GridCarouselProps) => {
|
}: GridCarouselProps) => {
|
||||||
const [direction, setDirection] = useState(0);
|
const [direction, setDirection] = useState(0);
|
||||||
|
|
||||||
|
@ -148,12 +153,13 @@ export const GridCarousel = ({
|
||||||
direction,
|
direction,
|
||||||
gridHeight,
|
gridHeight,
|
||||||
imageSize,
|
imageSize,
|
||||||
|
itemType,
|
||||||
loading,
|
loading,
|
||||||
pagination,
|
pagination,
|
||||||
setDirection,
|
setDirection,
|
||||||
uniqueId,
|
uniqueId,
|
||||||
}),
|
}),
|
||||||
[cardRows, data, direction, gridHeight, imageSize, loading, pagination, uniqueId],
|
[cardRows, data, direction, gridHeight, imageSize, itemType, loading, pagination, uniqueId],
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -177,6 +183,7 @@ interface TitleProps {
|
||||||
|
|
||||||
const Title = ({ children }: TitleProps) => {
|
const Title = ({ children }: TitleProps) => {
|
||||||
const { pagination, setDirection } = useContext(GridCarouselContext);
|
const { pagination, setDirection } = useContext(GridCarouselContext);
|
||||||
|
const showPaginationButtons = pagination?.handleNextPage && pagination?.handlePreviousPage;
|
||||||
|
|
||||||
const handleNextPage = useCallback(() => {
|
const handleNextPage = useCallback(() => {
|
||||||
setDirection(1);
|
setDirection(1);
|
||||||
|
@ -191,23 +198,25 @@ const Title = ({ children }: TitleProps) => {
|
||||||
return (
|
return (
|
||||||
<Group position="apart">
|
<Group position="apart">
|
||||||
{children}
|
{children}
|
||||||
<Group>
|
{showPaginationButtons && (
|
||||||
<Button
|
<Group>
|
||||||
compact
|
<Button
|
||||||
disabled={!pagination?.hasPreviousPage}
|
compact
|
||||||
variant="default"
|
disabled={!pagination?.hasPreviousPage}
|
||||||
onClick={handlePreviousPage}
|
variant="default"
|
||||||
>
|
onClick={handlePreviousPage}
|
||||||
<RiArrowLeftSLine size={15} />
|
>
|
||||||
</Button>
|
<RiArrowLeftSLine size={15} />
|
||||||
<Button
|
</Button>
|
||||||
compact
|
<Button
|
||||||
variant="default"
|
compact
|
||||||
onClick={handleNextPage}
|
variant="default"
|
||||||
>
|
onClick={handleNextPage}
|
||||||
<RiArrowRightSLine size={15} />
|
>
|
||||||
</Button>
|
<RiArrowRightSLine size={15} />
|
||||||
</Group>
|
</Button>
|
||||||
|
</Group>
|
||||||
|
)}
|
||||||
</Group>
|
</Group>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Reference in a new issue