2023-01-01 13:58:05 -08:00
|
|
|
import { useRef } from 'react';
|
2023-01-04 15:54:25 -08:00
|
|
|
import type { AgGridReact as AgGridReactType } from '@ag-grid-community/react/lib/agGridReact';
|
|
|
|
|
import { Stack } from '@mantine/core';
|
|
|
|
|
import { closeAllModals, openModal } from '@mantine/modals';
|
|
|
|
|
import { generatePath, useNavigate, useParams } from 'react-router';
|
2023-01-01 13:58:05 -08:00
|
|
|
import { PlaylistDetailSongListContent } from '../components/playlist-detail-song-list-content';
|
|
|
|
|
import { PlaylistDetailSongListHeader } from '../components/playlist-detail-song-list-header';
|
|
|
|
|
import { AnimatedPage } from '/@/renderer/features/shared';
|
2023-01-04 15:54:25 -08:00
|
|
|
import { PlaylistQueryBuilder } from '/@/renderer/features/playlists/components/playlist-query-builder';
|
|
|
|
|
import { usePlaylistDetail } from '/@/renderer/features/playlists/queries/playlist-detail-query';
|
|
|
|
|
import { useCreatePlaylist } from '/@/renderer/features/playlists/mutations/create-playlist-mutation';
|
|
|
|
|
import { AppRoute } from '/@/renderer/router/routes';
|
|
|
|
|
import { useDeletePlaylist } from '/@/renderer/features/playlists/mutations/delete-playlist-mutation';
|
|
|
|
|
import { Paper, toast } from '/@/renderer/components';
|
|
|
|
|
import { SaveAsPlaylistForm } from '/@/renderer/features/playlists/components/save-as-playlist-form';
|
2023-01-01 13:58:05 -08:00
|
|
|
|
|
|
|
|
const PlaylistDetailSongListRoute = () => {
|
2023-01-04 15:54:25 -08:00
|
|
|
const navigate = useNavigate();
|
2023-01-01 13:58:05 -08:00
|
|
|
const tableRef = useRef<AgGridReactType | null>(null);
|
|
|
|
|
const { playlistId } = useParams() as { playlistId: string };
|
|
|
|
|
|
2023-01-04 15:54:25 -08:00
|
|
|
const detailQuery = usePlaylistDetail({ id: playlistId });
|
|
|
|
|
const createPlaylistMutation = useCreatePlaylist();
|
|
|
|
|
const deletePlaylistMutation = useDeletePlaylist();
|
|
|
|
|
|
|
|
|
|
const handleSave = (filter: Record<string, any>) => {
|
|
|
|
|
const rules = {
|
|
|
|
|
...filter,
|
|
|
|
|
order: 'desc',
|
|
|
|
|
sort: 'year',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!detailQuery?.data) return;
|
|
|
|
|
|
|
|
|
|
createPlaylistMutation.mutate(
|
|
|
|
|
{
|
|
|
|
|
body: {
|
|
|
|
|
comment: detailQuery?.data?.description || '',
|
|
|
|
|
name: detailQuery?.data?.name,
|
|
|
|
|
ndParams: {
|
|
|
|
|
owner: detailQuery?.data?.owner || '',
|
|
|
|
|
ownerId: detailQuery?.data?.ownerId || '',
|
|
|
|
|
public: detailQuery?.data?.public || false,
|
|
|
|
|
rules,
|
|
|
|
|
sync: detailQuery?.data?.sync || false,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
onSuccess: (data) => {
|
|
|
|
|
toast.success({ message: 'Smart playlist saved' });
|
|
|
|
|
navigate(generatePath(AppRoute.PLAYLISTS_DETAIL_SONGS, { playlistId: data?.id || '' }), {
|
|
|
|
|
replace: true,
|
|
|
|
|
});
|
|
|
|
|
deletePlaylistMutation.mutate({ query: { id: playlistId } });
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleSaveAs = (filter: Record<string, any>) => {
|
|
|
|
|
openModal({
|
|
|
|
|
children: (
|
|
|
|
|
<SaveAsPlaylistForm
|
|
|
|
|
body={{
|
|
|
|
|
comment: detailQuery?.data?.description || '',
|
|
|
|
|
name: detailQuery?.data?.name,
|
|
|
|
|
ndParams: {
|
|
|
|
|
owner: detailQuery?.data?.owner || '',
|
|
|
|
|
ownerId: detailQuery?.data?.ownerId || '',
|
|
|
|
|
public: detailQuery?.data?.public || false,
|
|
|
|
|
rules: {
|
|
|
|
|
...filter,
|
|
|
|
|
order: 'desc',
|
|
|
|
|
sort: 'year',
|
|
|
|
|
},
|
|
|
|
|
sync: detailQuery?.data?.sync || false,
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
onCancel={closeAllModals}
|
|
|
|
|
onSuccess={(data) =>
|
|
|
|
|
navigate(generatePath(AppRoute.PLAYLISTS_DETAIL_SONGS, { playlistId: data?.id || '' }))
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
),
|
|
|
|
|
title: 'Save as',
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-01 13:58:05 -08:00
|
|
|
return (
|
|
|
|
|
<AnimatedPage key={`playlist-detail-songList-${playlistId}`}>
|
2023-01-04 15:54:25 -08:00
|
|
|
<Stack
|
|
|
|
|
h="100%"
|
|
|
|
|
spacing={0}
|
|
|
|
|
>
|
2023-01-01 13:58:05 -08:00
|
|
|
<PlaylistDetailSongListHeader tableRef={tableRef} />
|
2023-01-04 15:54:25 -08:00
|
|
|
<Paper
|
|
|
|
|
sx={{
|
|
|
|
|
maxHeight: '35vh',
|
|
|
|
|
padding: '1rem',
|
|
|
|
|
}}
|
|
|
|
|
w="100%"
|
|
|
|
|
>
|
|
|
|
|
{!detailQuery?.isLoading && (
|
|
|
|
|
<PlaylistQueryBuilder
|
|
|
|
|
query={detailQuery?.data?.rules || { all: [] }}
|
|
|
|
|
onSave={handleSave}
|
|
|
|
|
onSaveAs={handleSaveAs}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</Paper>
|
2023-01-01 13:58:05 -08:00
|
|
|
<PlaylistDetailSongListContent tableRef={tableRef} />
|
2023-01-04 15:54:25 -08:00
|
|
|
</Stack>
|
2023-01-01 13:58:05 -08:00
|
|
|
</AnimatedPage>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default PlaylistDetailSongListRoute;
|