Delete playlist added
This commit is contained in:
parent
8daf0cd526
commit
7e08b0e567
@ -140,6 +140,15 @@ export default function RekordboxReader() {
|
|||||||
document.body.removeChild(a);
|
document.body.removeChild(a);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handlePlaylistDelete = async (name: string) => {
|
||||||
|
const updatedPlaylists = playlists.filter(p => p.name !== name);
|
||||||
|
const savedPlaylists = await api.savePlaylists(updatedPlaylists);
|
||||||
|
setPlaylists(savedPlaylists);
|
||||||
|
if (currentPlaylist === name) {
|
||||||
|
navigate("/"); // Navigate back to All Songs if the current playlist is deleted
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const displayedSongs = currentPlaylist === "All Songs"
|
const displayedSongs = currentPlaylist === "All Songs"
|
||||||
? songs
|
? songs
|
||||||
: songs.filter((song) =>
|
: songs.filter((song) =>
|
||||||
@ -180,6 +189,7 @@ export default function RekordboxReader() {
|
|||||||
selectedItem={currentPlaylist}
|
selectedItem={currentPlaylist}
|
||||||
onPlaylistCreate={handleCreatePlaylist}
|
onPlaylistCreate={handleCreatePlaylist}
|
||||||
onPlaylistSelect={handlePlaylistSelect}
|
onPlaylistSelect={handlePlaylistSelect}
|
||||||
|
onPlaylistDelete={handlePlaylistDelete}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
<Box flex={1}>
|
<Box flex={1}>
|
||||||
|
|||||||
@ -13,7 +13,13 @@ import {
|
|||||||
Text,
|
Text,
|
||||||
useDisclosure,
|
useDisclosure,
|
||||||
VStack,
|
VStack,
|
||||||
|
Menu,
|
||||||
|
MenuButton,
|
||||||
|
MenuList,
|
||||||
|
MenuItem,
|
||||||
|
IconButton,
|
||||||
} from "@chakra-ui/react";
|
} from "@chakra-ui/react";
|
||||||
|
import { ChevronDownIcon, DeleteIcon } from "@chakra-ui/icons";
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { Playlist } from "../types/Playlist";
|
import { Playlist } from "../types/Playlist";
|
||||||
|
|
||||||
@ -21,7 +27,8 @@ interface PlaylistManagerProps {
|
|||||||
playlists: Playlist[];
|
playlists: Playlist[];
|
||||||
selectedItem: string | null;
|
selectedItem: string | null;
|
||||||
onPlaylistCreate: (name: string) => void;
|
onPlaylistCreate: (name: string) => void;
|
||||||
onPlaylistSelect: (id: string | null) => void;
|
onPlaylistSelect: (name: string | null) => void;
|
||||||
|
onPlaylistDelete: (name: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const getButtonStyles = (isSelected: boolean) => ({
|
const getButtonStyles = (isSelected: boolean) => ({
|
||||||
@ -48,6 +55,7 @@ export const PlaylistManager: React.FC<PlaylistManagerProps> = ({
|
|||||||
selectedItem,
|
selectedItem,
|
||||||
onPlaylistCreate,
|
onPlaylistCreate,
|
||||||
onPlaylistSelect,
|
onPlaylistSelect,
|
||||||
|
onPlaylistDelete,
|
||||||
}) => {
|
}) => {
|
||||||
const { isOpen, onOpen, onClose } = useDisclosure();
|
const { isOpen, onOpen, onClose } = useDisclosure();
|
||||||
const [newPlaylistName, setNewPlaylistName] = useState("");
|
const [newPlaylistName, setNewPlaylistName] = useState("");
|
||||||
@ -70,13 +78,37 @@ export const PlaylistManager: React.FC<PlaylistManagerProps> = ({
|
|||||||
All Songs
|
All Songs
|
||||||
</Button>
|
</Button>
|
||||||
{playlists.map((playlist) => (
|
{playlists.map((playlist) => (
|
||||||
|
<Flex key={playlist._id} align="center" gap={1}>
|
||||||
<Button
|
<Button
|
||||||
key={playlist._id}
|
flex={1}
|
||||||
{...getButtonStyles(selectedItem === playlist.name)}
|
{...getButtonStyles(selectedItem === playlist.name)}
|
||||||
onClick={() => onPlaylistSelect(playlist.name)}
|
onClick={() => onPlaylistSelect(playlist.name)}
|
||||||
>
|
>
|
||||||
{playlist.name}
|
{playlist.name}
|
||||||
</Button>
|
</Button>
|
||||||
|
<Menu>
|
||||||
|
<MenuButton
|
||||||
|
as={IconButton}
|
||||||
|
aria-label="Playlist options"
|
||||||
|
icon={<ChevronDownIcon />}
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
color="gray.400"
|
||||||
|
_hover={{ color: "white", bg: "whiteAlpha.200" }}
|
||||||
|
/>
|
||||||
|
<MenuList bg="gray.800" borderColor="gray.700">
|
||||||
|
<MenuItem
|
||||||
|
bg="gray.800"
|
||||||
|
color="red.300"
|
||||||
|
_hover={{ bg: "gray.700" }}
|
||||||
|
icon={<DeleteIcon />}
|
||||||
|
onClick={() => onPlaylistDelete(playlist.name)}
|
||||||
|
>
|
||||||
|
Delete Playlist
|
||||||
|
</MenuItem>
|
||||||
|
</MenuList>
|
||||||
|
</Menu>
|
||||||
|
</Flex>
|
||||||
))}
|
))}
|
||||||
</VStack>
|
</VStack>
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user