From 28ff98ab32bb2f800cc3d2a942c957d8a8337bf5 Mon Sep 17 00:00:00 2001 From: Ethan Girouard Date: Fri, 10 May 2024 20:22:59 -0400 Subject: [PATCH] Add LikeDislike component --- src/playbar.rs | 70 +++++++++++++++++++++++++++++++++++++++++++++++ src/playstatus.rs | 6 ++++ 2 files changed, 76 insertions(+) diff --git a/src/playbar.rs b/src/playbar.rs index 9d76b59..a3a9333 100644 --- a/src/playbar.rs +++ b/src/playbar.rs @@ -278,6 +278,75 @@ fn MediaInfo(status: RwSignal) -> impl IntoView { } } +/// The like and dislike buttons +#[component] +fn LikeDislike(status: RwSignal) -> impl IntoView { + let like_icon = Signal::derive(move || { + status.with(|status| { + if status.liked { + icondata::TbThumbUpFilled + } else { + icondata::TbThumbUp + } + }) + }); + + let dislike_icon = Signal::derive(move || { + status.with(|status| { + if status.disliked { + icondata::TbThumbDownFilled + } else { + icondata::TbThumbDown + } + }) + }); + + let toggle_like = move |_| { + status.update(|status| { + if status.queue.is_empty() { + return; + } + + status.liked = !status.liked; + + if status.liked { + status.disliked = false; + } + + // TODO call the API to like the song + }); + }; + + let toggle_dislike = move |_| { + status.update(|status| { + if status.queue.is_empty() { + return; + } + + status.disliked = !status.disliked; + + if status.disliked { + status.liked = false; + } + + // TODO call the API to dislike the song + }); + }; + + // TODO update like and dislike status using the API when a new song starts playing + + view! { + + } +} + /// The play progress bar, and click handler for skipping to a certain time in the song #[component] fn ProgressBar(percentage: MaybeSignal, status: RwSignal) -> impl IntoView { @@ -488,6 +557,7 @@ pub fn PlayBar(status: RwSignal) -> impl IntoView {
+
diff --git a/src/playstatus.rs b/src/playstatus.rs index 5952ee9..42b4774 100644 --- a/src/playstatus.rs +++ b/src/playstatus.rs @@ -17,6 +17,10 @@ pub struct PlayStatus { pub history: VecDeque, /// A queue of songs that have yet to be played, ordered from next up to last pub queue: VecDeque, + /// Whether the current playing song is liked + pub liked: bool, + /// Whether the current playing song is disliked + pub disliked: bool, } impl PlayStatus { @@ -59,6 +63,8 @@ impl Default for PlayStatus { audio_player: None, history: VecDeque::new(), queue: VecDeque::new(), + liked: false, + disliked: false, } } }