added the watch/unwatch buttons for artists/albums

This commit is contained in:
Connor Johnstone
2026-03-25 15:08:37 -04:00
parent d20989f859
commit a893a84f16
4 changed files with 158 additions and 57 deletions

View File

@@ -64,18 +64,76 @@ pub fn library_page() -> Html {
<tbody>
{ for artists.iter().map(|a| {
let artist_id = a.id;
let error = error.clone();
let fetch = fetch_artists.clone();
let on_remove = Callback::from(move |_: MouseEvent| {
let artist_name = a.name.clone();
let artist_mbid = a.musicbrainz_id.clone();
let is_watched = a.total_watched > 0;
let is_fully_watched = a.enriched && a.total_watched >= a.total_items && a.total_items > 0;
let is_monitored = a.monitored;
let on_remove = {
let error = error.clone();
let fetch = fetch.clone();
wasm_bindgen_futures::spawn_local(async move {
match api::delete_artist(artist_id).await {
Ok(_) => fetch.emit(()),
Err(e) => error.set(Some(e.0)),
}
});
});
let fetch = fetch_artists.clone();
Callback::from(move |_: MouseEvent| {
let error = error.clone();
let fetch = fetch.clone();
wasm_bindgen_futures::spawn_local(async move {
match api::delete_artist(artist_id).await {
Ok(_) => fetch.emit(()),
Err(e) => error.set(Some(e.0)),
}
});
})
};
let on_watch = {
let error = error.clone();
let fetch = fetch_artists.clone();
let name = artist_name.clone();
let mbid = artist_mbid.clone();
Callback::from(move |_: MouseEvent| {
let error = error.clone();
let fetch = fetch.clone();
let name = name.clone();
let mbid = mbid.clone();
wasm_bindgen_futures::spawn_local(async move {
match api::add_artist(&name, mbid.as_deref()).await {
Ok(_) => fetch.emit(()),
Err(e) => error.set(Some(e.0)),
}
});
})
};
let on_unwatch = {
let error = error.clone();
let fetch = fetch_artists.clone();
Callback::from(move |_: MouseEvent| {
let error = error.clone();
let fetch = fetch.clone();
wasm_bindgen_futures::spawn_local(async move {
match api::unwatch_artist(artist_id).await {
Ok(_) => fetch.emit(()),
Err(e) => error.set(Some(e.0)),
}
});
})
};
let on_monitor_toggle = {
let error = error.clone();
let fetch = fetch_artists.clone();
Callback::from(move |_: MouseEvent| {
let error = error.clone();
let fetch = fetch.clone();
wasm_bindgen_futures::spawn_local(async move {
match api::set_artist_monitored(artist_id, !is_monitored).await {
Ok(_) => fetch.emit(()),
Err(e) => error.set(Some(e.0)),
}
});
})
};
html! {
<tr>
<td>
@@ -116,8 +174,22 @@ pub fn library_page() -> Html {
{ a.total_items }
}
</td>
<td>
<button class="btn btn-sm btn-danger" onclick={on_remove}>
<td class="actions">
<button class="btn btn-sm btn-lib"
onclick={on_watch}
style={if is_fully_watched { "visibility:hidden;" } else { "" }}>
{ "Watch" }
</button>
<button class="btn btn-sm btn-secondary btn-lib"
onclick={on_unwatch}
style={if !is_watched { "visibility:hidden;" } else { "" }}>
{ "Unwatch" }
</button>
<button class={if is_monitored { "btn btn-sm btn-success btn-lib" } else { "btn btn-sm btn-secondary btn-lib" }}
onclick={on_monitor_toggle}>
{ if is_monitored { "Monitored" } else { "Monitor" } }
</button>
<button class="btn btn-sm btn-danger btn-lib" onclick={on_remove}>
{ "Remove" }
</button>
</td>