2022-12-31 03:46:12 -08:00
|
|
|
import type { AgGridReact as AgGridReactType } from '@ag-grid-community/react/lib/agGridReact';
|
2023-02-07 22:47:23 -08:00
|
|
|
import { Flex, Stack } from '@mantine/core';
|
2023-05-21 15:02:57 -07:00
|
|
|
import { openModal, closeAllModals } from '@mantine/modals';
|
2023-02-05 22:41:47 -08:00
|
|
|
import { MutableRefObject } from 'react';
|
2023-05-21 15:02:57 -07:00
|
|
|
import { PageHeader, SpinnerIcon, Paper, Button } from '/@/renderer/components';
|
|
|
|
|
import { CreatePlaylistForm } from '/@/renderer/features/playlists/components/create-playlist-form';
|
2023-02-05 22:41:47 -08:00
|
|
|
import { PlaylistListHeaderFilters } from '/@/renderer/features/playlists/components/playlist-list-header-filters';
|
|
|
|
|
import { LibraryHeaderBar } from '/@/renderer/features/shared';
|
2022-12-31 03:46:12 -08:00
|
|
|
import { useContainerQuery } from '/@/renderer/hooks';
|
2023-05-21 15:02:57 -07:00
|
|
|
import { useCurrentServer } from '/@/renderer/store';
|
|
|
|
|
import { ServerType } from '/@/renderer/types';
|
2022-12-31 03:46:12 -08:00
|
|
|
|
|
|
|
|
interface PlaylistListHeaderProps {
|
2023-02-05 22:41:47 -08:00
|
|
|
itemCount?: number;
|
2022-12-31 03:46:12 -08:00
|
|
|
tableRef: MutableRefObject<AgGridReactType | null>;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-05 22:41:47 -08:00
|
|
|
export const PlaylistListHeader = ({ itemCount, tableRef }: PlaylistListHeaderProps) => {
|
2022-12-31 03:46:12 -08:00
|
|
|
const cq = useContainerQuery();
|
2023-05-21 15:02:57 -07:00
|
|
|
const server = useCurrentServer();
|
|
|
|
|
|
|
|
|
|
const handleCreatePlaylistModal = () => {
|
|
|
|
|
openModal({
|
|
|
|
|
children: <CreatePlaylistForm onCancel={() => closeAllModals()} />,
|
|
|
|
|
onClose: () => {
|
|
|
|
|
tableRef?.current?.api?.purgeInfiniteCache();
|
|
|
|
|
},
|
2023-05-21 17:53:43 -07:00
|
|
|
size: server?.type === ServerType?.NAVIDROME ? 'xl' : 'sm',
|
2023-05-21 15:02:57 -07:00
|
|
|
title: 'Create Playlist',
|
|
|
|
|
});
|
|
|
|
|
};
|
2022-12-31 03:46:12 -08:00
|
|
|
|
|
|
|
|
return (
|
2023-02-05 22:41:47 -08:00
|
|
|
<Stack
|
|
|
|
|
ref={cq.ref}
|
|
|
|
|
spacing={0}
|
|
|
|
|
>
|
|
|
|
|
<PageHeader backgroundColor="var(--titlebar-bg)">
|
2023-05-21 15:02:57 -07:00
|
|
|
<Flex
|
|
|
|
|
align="center"
|
|
|
|
|
justify="space-between"
|
|
|
|
|
w="100%"
|
|
|
|
|
>
|
2023-02-05 22:41:47 -08:00
|
|
|
<LibraryHeaderBar>
|
2023-02-07 22:47:23 -08:00
|
|
|
<LibraryHeaderBar.Title>Playlists</LibraryHeaderBar.Title>
|
2023-02-05 22:41:47 -08:00
|
|
|
<Paper
|
|
|
|
|
fw="600"
|
|
|
|
|
px="1rem"
|
|
|
|
|
py="0.3rem"
|
|
|
|
|
radius="sm"
|
|
|
|
|
>
|
|
|
|
|
{itemCount === null || itemCount === undefined ? <SpinnerIcon /> : itemCount}
|
|
|
|
|
</Paper>
|
|
|
|
|
</LibraryHeaderBar>
|
2023-05-21 15:02:57 -07:00
|
|
|
<Button onClick={handleCreatePlaylistModal}>Create playlist</Button>
|
2022-12-31 03:46:12 -08:00
|
|
|
</Flex>
|
2023-02-05 22:41:47 -08:00
|
|
|
</PageHeader>
|
2023-02-06 02:17:47 -08:00
|
|
|
<Paper p="1rem">
|
2023-02-05 22:41:47 -08:00
|
|
|
<PlaylistListHeaderFilters tableRef={tableRef} />
|
|
|
|
|
</Paper>
|
|
|
|
|
</Stack>
|
2022-12-31 03:46:12 -08:00
|
|
|
);
|
|
|
|
|
};
|