Add LikeDislike component

This commit is contained in:
Ethan Girouard 2024-05-10 20:22:59 -04:00
parent a0da89204c
commit 28ff98ab32
Signed by: eta357
GPG Key ID: 7BCDC36DFD11C146
2 changed files with 76 additions and 0 deletions

View File

@ -278,6 +278,75 @@ fn MediaInfo(status: RwSignal<PlayStatus>) -> impl IntoView {
} }
} }
/// The like and dislike buttons
#[component]
fn LikeDislike(status: RwSignal<PlayStatus>) -> 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! {
<div class="like-dislike">
<button on:click=toggle_dislike>
<Icon class="controlbtn hmirror" width=SKIP_BTN_SIZE height=SKIP_BTN_SIZE icon=dislike_icon />
</button>
<button on:click=toggle_like>
<Icon class="controlbtn" width=SKIP_BTN_SIZE height=SKIP_BTN_SIZE icon=like_icon />
</button>
</div>
}
}
/// The play progress bar, and click handler for skipping to a certain time in the song /// The play progress bar, and click handler for skipping to a certain time in the song
#[component] #[component]
fn ProgressBar(percentage: MaybeSignal<f64>, status: RwSignal<PlayStatus>) -> impl IntoView { fn ProgressBar(percentage: MaybeSignal<f64>, status: RwSignal<PlayStatus>) -> impl IntoView {
@ -488,6 +557,7 @@ pub fn PlayBar(status: RwSignal<PlayStatus>) -> impl IntoView {
<ProgressBar percentage=percentage.into() status=status /> <ProgressBar percentage=percentage.into() status=status />
<div class="playbar-left-group"> <div class="playbar-left-group">
<MediaInfo status=status /> <MediaInfo status=status />
<LikeDislike status=status />
</div> </div>
<PlayControls status=status /> <PlayControls status=status />
<PlayDuration elapsed_secs=elapsed_secs.into() total_secs=total_secs.into() /> <PlayDuration elapsed_secs=elapsed_secs.into() total_secs=total_secs.into() />

View File

@ -17,6 +17,10 @@ pub struct PlayStatus {
pub history: VecDeque<SongData>, pub history: VecDeque<SongData>,
/// A queue of songs that have yet to be played, ordered from next up to last /// A queue of songs that have yet to be played, ordered from next up to last
pub queue: VecDeque<SongData>, pub queue: VecDeque<SongData>,
/// Whether the current playing song is liked
pub liked: bool,
/// Whether the current playing song is disliked
pub disliked: bool,
} }
impl PlayStatus { impl PlayStatus {
@ -59,6 +63,8 @@ impl Default for PlayStatus {
audio_player: None, audio_player: None,
history: VecDeque::new(), history: VecDeque::new(),
queue: VecDeque::new(), queue: VecDeque::new(),
liked: false,
disliked: false,
} }
} }
} }