From 280b8db49e901318d7533e9b3ccc7865b25bcb25 Mon Sep 17 00:00:00 2001 From: MrDulfin Date: Sat, 28 Dec 2024 00:19:08 -0500 Subject: [PATCH] Added Queue Navigation and removal --- src-tauri/src/lib.rs | 5 +++-- src-tauri/src/wrappers.rs | 8 ++++---- src/App.tsx | 27 +++++++++++++++++++++------ 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 7e74b34..22f50ca 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -6,7 +6,7 @@ use dmp_core::{config::{Config, ConfigLibrary}, music_controller::controller::{C use tauri::{http::Response, Emitter, Manager, State, WebviewWindowBuilder, Wry}; use uuid::Uuid; -use crate::wrappers::{get_library, play, pause, prev, set_volume, get_song, next, get_queue, import_playlist, get_playlist, get_playlists}; +use crate::wrappers::{get_library, play, pause, prev, set_volume, get_song, next, get_queue, import_playlist, get_playlist, get_playlists, remove_from_queue}; pub mod wrappers; pub mod commands; @@ -80,7 +80,8 @@ pub fn run() { play_now, import_playlist, get_playlist, - get_playlists + get_playlists, + remove_from_queue ]).manage(ConfigRx(rx)) .manage(LibRx(lib_rx)) .manage(HandleTx(handle_tx)) diff --git a/src-tauri/src/wrappers.rs b/src-tauri/src/wrappers.rs index c982e73..2bce23b 100644 --- a/src-tauri/src/wrappers.rs +++ b/src-tauri/src/wrappers.rs @@ -2,7 +2,7 @@ use std::{collections::BTreeMap, path::PathBuf}; use chrono::{DateTime, Utc, serde::ts_milliseconds_option}; use crossbeam::channel::Sender; -use dmp_core::{music_controller::controller::{ControllerHandle, LibraryCommand, LibraryResponse, PlayerResponse, QueueCommand, QueueResponse}, music_storage::library::{Song, Tag, URI}}; +use dmp_core::{music_controller::controller::{ControllerHandle, LibraryCommand, LibraryResponse, PlayerLocation, PlayerResponse, QueueCommand, QueueResponse}, music_storage::library::{Song, Tag, URI}}; use itertools::Itertools; use kushi::QueueItemType; use serde::Serialize; @@ -78,7 +78,7 @@ pub async fn now_playing(ctrl_handle: State<'_, ControllerHandle>) -> Result<(), } #[tauri::command] -pub async fn get_queue(ctrl_handle: State<'_, ControllerHandle>) -> Result, String> { +pub async fn get_queue(ctrl_handle: State<'_, ControllerHandle>) -> Result, String> { Ok( ctrl_handle .queue_get_all() @@ -86,14 +86,14 @@ pub async fn get_queue(ctrl_handle: State<'_, ControllerHandle>) -> Result, ctrl_handle: ControllerHandle, index: usize) -> Result<(), String> { +pub async fn remove_from_queue(app: AppHandle, ctrl_handle: State<'_, ControllerHandle>, index: usize) -> Result<(), String> { match ctrl_handle.queue_remove(index).await { Ok(_) => { app.emit("queue_updated", ()).unwrap(); diff --git a/src/App.tsx b/src/App.tsx index 0210f99..ac331d5 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -47,7 +47,14 @@ function App() { invoke('get_queue').then((_songs) => { let songs = _songs as any[] setQueue( - songs.filter((_, i) => i != 0).map((song) => ) + songs.filter((_, i) => i != 0).map((song, i) => + + ) ) }) }) @@ -329,22 +336,30 @@ function Queue({ songs }: QueueProps) { } interface QueueSongProps { - song: any + song: any, + location: "Library" | {"Playlist": string}, + index: number, } -function QueueSong({ song }: QueueSongProps) { +function QueueSong({ song, location, index }: QueueSongProps) { console.log(song.tags); + let removeFromQueue = () => { + invoke('remove_from_queue', { index: index }).then(() => {}) + } + + let playNow = () => { + invoke('play_now', { uuid: song.uuid, location: location }).then(() => {}) + } + return ( - // ) }