2023-01-02 02:04:23 -08:00
|
|
|
import { Group, Stack } from '@mantine/core';
|
2023-01-03 00:28:09 -08:00
|
|
|
import { closeAllModals, openModal } from '@mantine/modals';
|
2023-01-03 03:25:21 -08:00
|
|
|
import { forwardRef, Fragment, Ref } from 'react';
|
2023-01-02 02:04:23 -08:00
|
|
|
import { RiMoreFill } from 'react-icons/ri';
|
2023-01-03 00:28:09 -08:00
|
|
|
import { generatePath, useNavigate, useParams } from 'react-router';
|
2023-01-02 02:04:23 -08:00
|
|
|
import { Link } from 'react-router-dom';
|
2023-01-03 03:25:21 -08:00
|
|
|
import { DropdownMenu, Button, ConfirmModal, toast, Text } from '/@/renderer/components';
|
2023-01-02 02:04:23 -08:00
|
|
|
import { usePlayQueueAdd } from '/@/renderer/features/player';
|
2023-01-03 00:28:09 -08:00
|
|
|
import { UpdatePlaylistForm } from './update-playlist-form';
|
|
|
|
|
import { useDeletePlaylist } from '/@/renderer/features/playlists/mutations/delete-playlist-mutation';
|
2023-01-02 02:04:23 -08:00
|
|
|
import { usePlaylistDetail } from '/@/renderer/features/playlists/queries/playlist-detail-query';
|
|
|
|
|
import { LibraryHeader, PlayButton, PLAY_TYPES } from '/@/renderer/features/shared';
|
|
|
|
|
import { AppRoute } from '/@/renderer/router/routes';
|
|
|
|
|
import { usePlayButtonBehavior } from '/@/renderer/store/settings.store';
|
|
|
|
|
import { LibraryItem, Play } from '/@/renderer/types';
|
2023-01-03 03:25:21 -08:00
|
|
|
import { formatDurationString } from '/@/renderer/utils';
|
2023-01-02 02:04:23 -08:00
|
|
|
|
|
|
|
|
interface PlaylistDetailHeaderProps {
|
|
|
|
|
background: string;
|
|
|
|
|
imagePlaceholderUrl?: string | null;
|
|
|
|
|
imageUrl?: string | null;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-02 17:57:49 -08:00
|
|
|
export const PlaylistDetailHeader = forwardRef(
|
|
|
|
|
(
|
|
|
|
|
{ background, imageUrl, imagePlaceholderUrl }: PlaylistDetailHeaderProps,
|
|
|
|
|
ref: Ref<HTMLDivElement>,
|
|
|
|
|
) => {
|
2023-01-03 00:28:09 -08:00
|
|
|
const navigate = useNavigate();
|
2023-01-02 17:57:49 -08:00
|
|
|
const { playlistId } = useParams() as { playlistId: string };
|
|
|
|
|
const detailQuery = usePlaylistDetail({ id: playlistId });
|
|
|
|
|
const handlePlayQueueAdd = usePlayQueueAdd();
|
|
|
|
|
const playButtonBehavior = usePlayButtonBehavior();
|
2023-01-02 02:04:23 -08:00
|
|
|
|
2023-01-02 17:57:49 -08:00
|
|
|
const handlePlay = (playType?: Play) => {
|
|
|
|
|
handlePlayQueueAdd?.({
|
|
|
|
|
byItemType: {
|
|
|
|
|
id: [playlistId],
|
|
|
|
|
type: LibraryItem.PLAYLIST,
|
|
|
|
|
},
|
|
|
|
|
play: playType || playButtonBehavior,
|
|
|
|
|
});
|
|
|
|
|
};
|
2023-01-02 02:04:23 -08:00
|
|
|
|
2023-01-03 00:28:09 -08:00
|
|
|
const openUpdatePlaylistModal = () => {
|
|
|
|
|
openModal({
|
|
|
|
|
children: (
|
|
|
|
|
<UpdatePlaylistForm
|
|
|
|
|
body={{
|
|
|
|
|
comment: detailQuery?.data?.description || undefined,
|
2023-01-03 03:25:21 -08:00
|
|
|
genres: detailQuery?.data?.genres,
|
2023-01-03 00:28:09 -08:00
|
|
|
name: detailQuery?.data?.name,
|
|
|
|
|
public: detailQuery?.data?.public || false,
|
|
|
|
|
rules: detailQuery?.data?.rules || undefined,
|
|
|
|
|
}}
|
|
|
|
|
query={{ id: playlistId }}
|
|
|
|
|
onCancel={closeAllModals}
|
|
|
|
|
/>
|
|
|
|
|
),
|
|
|
|
|
title: 'Edit playlist',
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const deletePlaylistMutation = useDeletePlaylist();
|
|
|
|
|
|
|
|
|
|
const handleDeletePlaylist = () => {
|
|
|
|
|
deletePlaylistMutation.mutate(
|
|
|
|
|
{ query: { id: playlistId } },
|
|
|
|
|
{
|
|
|
|
|
onError: (err) => {
|
|
|
|
|
toast.error({
|
|
|
|
|
message: err.message,
|
|
|
|
|
title: 'Error deleting playlist',
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
onSuccess: () => {
|
|
|
|
|
toast.success({
|
|
|
|
|
message: `${detailQuery?.data?.name} was successfully deleted`,
|
|
|
|
|
title: 'Playlist deleted',
|
|
|
|
|
});
|
|
|
|
|
closeAllModals();
|
|
|
|
|
navigate(AppRoute.PLAYLISTS);
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const openDeletePlaylist = () => {
|
|
|
|
|
openModal({
|
|
|
|
|
children: (
|
|
|
|
|
<ConfirmModal
|
|
|
|
|
loading={deletePlaylistMutation.isLoading}
|
|
|
|
|
onConfirm={handleDeletePlaylist}
|
|
|
|
|
>
|
|
|
|
|
Are you sure you want to delete this playlist?
|
|
|
|
|
</ConfirmModal>
|
|
|
|
|
),
|
|
|
|
|
title: 'Delete playlist',
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-03 03:25:21 -08:00
|
|
|
const metadataItems = [
|
|
|
|
|
{
|
|
|
|
|
id: 'songCount',
|
|
|
|
|
secondary: false,
|
|
|
|
|
value: `${detailQuery?.data?.songCount || 0} songs`,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'duration',
|
|
|
|
|
secondary: true,
|
|
|
|
|
value: detailQuery?.data?.duration && formatDurationString(detailQuery.data.duration),
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
2023-01-02 17:57:49 -08:00
|
|
|
return (
|
|
|
|
|
<Stack>
|
|
|
|
|
<LibraryHeader
|
|
|
|
|
ref={ref}
|
|
|
|
|
background={background}
|
|
|
|
|
imagePlaceholderUrl={imagePlaceholderUrl}
|
|
|
|
|
imageUrl={imageUrl}
|
|
|
|
|
item={{ route: AppRoute.PLAYLISTS, type: LibraryItem.PLAYLIST }}
|
|
|
|
|
title={detailQuery?.data?.name || ''}
|
|
|
|
|
>
|
2023-01-03 03:25:21 -08:00
|
|
|
<Stack mt="1rem">
|
|
|
|
|
<Group>
|
|
|
|
|
{metadataItems.map((item, index) => (
|
|
|
|
|
<Fragment key={`item-${item.id}-${index}`}>
|
|
|
|
|
{index > 0 && <Text $noSelect>•</Text>}
|
|
|
|
|
<Text $secondary={item.secondary}>{item.value}</Text>
|
|
|
|
|
</Fragment>
|
|
|
|
|
))}
|
|
|
|
|
</Group>
|
|
|
|
|
<Text lineClamp={3}>{detailQuery?.data?.description}</Text>
|
|
|
|
|
</Stack>
|
2023-01-02 17:57:49 -08:00
|
|
|
</LibraryHeader>
|
|
|
|
|
<Group
|
|
|
|
|
maw="1920px"
|
|
|
|
|
p="1rem"
|
|
|
|
|
position="apart"
|
|
|
|
|
>
|
|
|
|
|
<Group>
|
|
|
|
|
<PlayButton onClick={() => handlePlay()} />
|
|
|
|
|
<DropdownMenu position="bottom-start">
|
|
|
|
|
<DropdownMenu.Target>
|
|
|
|
|
<Button
|
|
|
|
|
compact
|
|
|
|
|
variant="subtle"
|
2023-01-02 02:04:23 -08:00
|
|
|
>
|
2023-01-02 17:57:49 -08:00
|
|
|
<RiMoreFill size={20} />
|
|
|
|
|
</Button>
|
|
|
|
|
</DropdownMenu.Target>
|
|
|
|
|
<DropdownMenu.Dropdown>
|
|
|
|
|
{PLAY_TYPES.filter((type) => type.play !== playButtonBehavior).map((type) => (
|
|
|
|
|
<DropdownMenu.Item
|
|
|
|
|
key={`playtype-${type.play}`}
|
|
|
|
|
onClick={() => handlePlay(type.play)}
|
|
|
|
|
>
|
|
|
|
|
{type.label}
|
|
|
|
|
</DropdownMenu.Item>
|
|
|
|
|
))}
|
|
|
|
|
<DropdownMenu.Divider />
|
2023-01-03 00:28:09 -08:00
|
|
|
<DropdownMenu.Item onClick={openUpdatePlaylistModal}>
|
|
|
|
|
Edit playlist
|
|
|
|
|
</DropdownMenu.Item>
|
|
|
|
|
<DropdownMenu.Item onClick={openDeletePlaylist}>Delete playlist</DropdownMenu.Item>
|
2023-01-02 17:57:49 -08:00
|
|
|
</DropdownMenu.Dropdown>
|
|
|
|
|
</DropdownMenu>
|
2023-01-03 03:25:21 -08:00
|
|
|
|
|
|
|
|
<Button
|
|
|
|
|
compact
|
|
|
|
|
component={Link}
|
|
|
|
|
to={generatePath(AppRoute.PLAYLISTS_DETAIL_SONGS, { playlistId })}
|
|
|
|
|
variant="subtle"
|
|
|
|
|
>
|
|
|
|
|
View full playlist
|
|
|
|
|
</Button>
|
2023-01-02 17:57:49 -08:00
|
|
|
</Group>
|
2023-01-02 02:04:23 -08:00
|
|
|
</Group>
|
2023-01-02 17:57:49 -08:00
|
|
|
</Stack>
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|