From 04898fe7f0ae869b8b2cf0d80b7ec422d3b36cc5 Mon Sep 17 00:00:00 2001 From: ecco257 <72117210+ecco257@users.noreply.github.com> Date: Tue, 6 Feb 2024 17:38:16 -0500 Subject: [PATCH] Add remove button for queue items --- src/queue.rs | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/src/queue.rs b/src/queue.rs index 2e69b55..1cf5f8d 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -1,6 +1,38 @@ use crate::playstatus::PlayStatus; +use crate::playbar::skip_to; +use crate::playbar::get_song_time_duration; +use crate::playbar::set_playing; +use leptos::ev::MouseEvent; use leptos::leptos_dom::*; use leptos::*; +use leptos_icons::*; +use leptos_icons::BsIcon::*; + +const RM_BTN_SIZE: &str = "2rem"; + +fn skip_to_next(status: RwSignal) { + + if let Some(duration) = get_song_time_duration(status) { + skip_to(status, duration.1); + set_playing(status, true); + } else { + error!("Unable to skip forward: Unable to get current duration"); + } +} + +fn remove_song_fn(index: usize, status: RwSignal) { + // handle the case when index is 0 (i.e. the first song in the queue is removed) + // if the song is currently playing, skip to the next song + if index == 0 { + log!("Remove Song from Queue: Song is currently playing, skipping to next song and adding to history"); + skip_to_next(status); + } else { + log!("Remove Song from Queue: Song is not currently playing, no need to skip to next song, instead deleting song from queue and not adding to history"); + status.update(|status| { + status.queue.remove(index); + }); + } +} #[component] fn Song(song_image_path: String, song_title: String, song_artist: String) -> impl IntoView { @@ -18,6 +50,15 @@ fn Song(song_image_path: String, song_title: String, song_artist: String) -> imp #[component] pub fn Queue(status: RwSignal) -> impl IntoView { + let remove_song = move |index: usize| { + remove_song_fn(index, status); + log!("Removed song {}", index + 1); + }; + + let prevent_focus = move |e: MouseEvent| { + e.prevent_default(); + }; + view!{ ) -> impl IntoView {
    { status.with(|status| status.queue.iter() - .map(|song| view! { - + .enumerate() + .map(|(index, song)| view! { +
    + + +
    }) .collect::>()) }