diff --git a/src/renderer/src/components/playlist/playlist-create/PlaylistCreateBox.tsx b/src/renderer/src/components/playlist/playlist-create/PlaylistCreateBox.tsx index e69ef44..ecac452 100644 --- a/src/renderer/src/components/playlist/playlist-create/PlaylistCreateBox.tsx +++ b/src/renderer/src/components/playlist/playlist-create/PlaylistCreateBox.tsx @@ -1,19 +1,21 @@ -import { noticeError } from "../playlist.utils"; +import { noticeError, setShowPlaylistCreateBox } from "../playlist.utils"; import Button from "@renderer/components/button/Button"; import { Input } from "@renderer/components/input/Input"; import { addNotice } from "@renderer/components/notice/NoticeContainer"; import SongImage from "@renderer/components/song/SongImage"; import Impulse from "@renderer/lib/Impulse"; import { CircleCheckIcon, XIcon } from "lucide-solid"; -import { Component, createSignal, Setter } from "solid-js"; +import { Component, createSignal, Signal } from "solid-js"; +import { Song } from "src/@types"; export type PlaylistCreateBoxProps = { group: string; - isOpen: Setter; reset: Impulse; + songSignal: Signal; }; const PlaylistCreateBox: Component = (props) => { const [playlistName, setPlaylistName] = createSignal(""); + const [createPlaylistBoxSong, setCreatePlaylistBoxSong] = props.songSignal; const createPlaylist = async () => { // last check is probably unnecessary @@ -29,7 +31,7 @@ const PlaylistCreateBox: Component = (props) => { setPlaylistName(""); props.reset.pulse(); - props.isOpen(false); + setShowPlaylistCreateBox(false); addNotice({ title: "Playlist created", @@ -37,20 +39,42 @@ const PlaylistCreateBox: Component = (props) => { variant: "success", icon: , }); + + const song = createPlaylistBoxSong(); + if (song !== undefined) { + const songResult = await window.api.request("playlist::add", name, song); + setCreatePlaylistBoxSong(undefined); + + if (songResult.isError) { + noticeError(songResult.error); + return; + } + + addNotice({ + title: "Song added", + description: "Successfully added song to playlist " + name + "!", + variant: "success", + icon: , + }); + } }; return (

Create a new playlist

-
{ const resetListing = new Impulse(); - const [showCreateBox, setShowCreateBox] = createSignal(false); - const group = namespace.create(true); - onMount(() => window.api.listen("playlist::resetList", resetListing.pulse.bind(resetListing))); - onCleanup(() => - window.api.removeListener("playlist::resetList", resetListing.pulse.bind(resetListing)), - ); + onMount(() => { + window.api.listen("playlist::resetList", resetListing.pulse.bind(resetListing)); + }); + + onCleanup(() => { + window.api.removeListener("playlist::resetList", resetListing.pulse.bind(resetListing)); + }); return (
@@ -39,17 +46,22 @@ const PlaylistList: Component = () => {
- - + +
diff --git a/src/renderer/src/components/playlist/playlist.utils.ts b/src/renderer/src/components/playlist/playlist.utils.ts index ee8b853..0ab5cbc 100644 --- a/src/renderer/src/components/playlist/playlist.utils.ts +++ b/src/renderer/src/components/playlist/playlist.utils.ts @@ -1,6 +1,6 @@ import { addNotice } from "../notice/NoticeContainer"; import Impulse from "@renderer/lib/Impulse"; -import { BadgeCheckIcon, CircleXIcon } from "lucide-solid"; +import { CircleCheckIcon, CircleXIcon } from "lucide-solid"; import { createSignal } from "solid-js"; import { Song } from "src/@types"; @@ -9,8 +9,13 @@ const PLAYLIST_SCENE_SONGS = 1; const [playlistActiveScene, setPlaylistActiveScene] = createSignal(PLAYLIST_SCENE_LIST); const [activePlaylistName, setActivePlaylistName] = createSignal(""); +const [createPlaylistBoxSong, setCreatePlaylistBoxSong] = createSignal(undefined); +const [showPlaylistCreateBox, setShowPlaylistCreateBox] = createSignal(false); + export { playlistActiveScene, setPlaylistActiveScene }; export { activePlaylistName, setActivePlaylistName }; +export { createPlaylistBoxSong, setCreatePlaylistBoxSong }; +export { showPlaylistCreateBox, setShowPlaylistCreateBox }; export { PLAYLIST_SCENE_SONGS, PLAYLIST_SCENE_LIST }; export function noticeError(error: string) { @@ -32,7 +37,7 @@ export async function deletePlaylist(name: string, reset: Impulse) { variant: "success", title: "Playlist deleted", description: "Playlist " + name + " successfully deleted!", - icon: BadgeCheckIcon({ size: 20 }), + icon: CircleCheckIcon({ size: 20 }), }); } } @@ -53,7 +58,7 @@ export async function renamePlaylist(oldName: string, newName: string) { title: "Renamed playlist", description: "Playlist renamed successfully!", variant: "success", - icon: BadgeCheckIcon({ size: 20 }), + icon: CircleCheckIcon({ size: 20 }), }); } diff --git a/src/renderer/src/components/song/context-menu/items/PlaylistChooser.tsx b/src/renderer/src/components/song/context-menu/items/PlaylistChooser.tsx index 6ce6930..815516e 100644 --- a/src/renderer/src/components/song/context-menu/items/PlaylistChooser.tsx +++ b/src/renderer/src/components/song/context-menu/items/PlaylistChooser.tsx @@ -1,7 +1,14 @@ import DropdownList from "@renderer/components/dropdown-list/DropdownList"; import { addNotice } from "@renderer/components/notice/NoticeContainer"; -import { noticeError } from "@renderer/components/playlist/playlist.utils"; -import { BadgeCheckIcon, CheckIcon } from "lucide-solid"; +import { + noticeError, + PLAYLIST_SCENE_LIST, + setCreatePlaylistBoxSong, + setPlaylistActiveScene, + setShowPlaylistCreateBox, +} from "@renderer/components/playlist/playlist.utils"; +import { setSidebarActiveTab, SIDEBAR_PAGES } from "@renderer/scenes/main-scene/main.utils"; +import { CheckIcon, CircleCheckIcon, PlusIcon } from "lucide-solid"; import { Accessor, Component, For, Setter, Show } from "solid-js"; import { Song } from "src/@types"; @@ -24,7 +31,7 @@ const PlaylistChooser: Component = (props) => { title: "Song added", description: "Successfully added song to playlist " + name + "!", variant: "success", - icon: , + icon: , }); }; @@ -37,7 +44,30 @@ const PlaylistChooser: Component = (props) => { }; return ( - + { + clearTimeout(props.timeoutId()); + }} + onMouseLeave={() => { + props.setTimeoutId( + setTimeout(() => { + props.setShowChooser(false); + }, 320), + ); + }} + class="max-h-[95vh] w-40 overflow-auto [scrollbar-width:none]" + > + { + setCreatePlaylistBoxSong(props.song); + setShowPlaylistCreateBox(true); + setSidebarActiveTab(SIDEBAR_PAGES.PLAYLISTS.value); + setPlaylistActiveScene(PLAYLIST_SCENE_LIST); + }} + > + Create Playlist + + No playlists...} each={props.playlistNames} @@ -47,16 +77,6 @@ const PlaylistChooser: Component = (props) => { onClick={() => { addToPlaylist(props.playlistNames[index()]); }} - onMouseOver={() => { - clearTimeout(props.timeoutId()); - }} - onMouseLeave={() => { - props.setTimeoutId( - setTimeout(() => { - props.setShowChooser(false); - }, 320), - ); - }} > {child}