added the watch/unwatch buttons for artists/albums
This commit is contained in:
@@ -109,37 +109,9 @@ pub fn artist_page(props: &Props) -> Html {
|
|||||||
let is_watched = d.artist_status == "owned"
|
let is_watched = d.artist_status == "owned"
|
||||||
|| d.artist_status == "partial"
|
|| d.artist_status == "partial"
|
||||||
|| d.artist_status == "wanted";
|
|| d.artist_status == "wanted";
|
||||||
if is_watched {
|
let is_fully_watched = d.artist_status == "owned";
|
||||||
// Unwatch All
|
|
||||||
let artist_id_num = d.artist.id;
|
let watch_btn = if !is_fully_watched {
|
||||||
let artist_name = d.artist.name.clone();
|
|
||||||
let message = message.clone();
|
|
||||||
let error = error.clone();
|
|
||||||
let fetch = fetch.clone();
|
|
||||||
let artist_id = id.clone();
|
|
||||||
html! {
|
|
||||||
<button class="btn btn-sm btn-secondary"
|
|
||||||
onclick={Callback::from(move |_: MouseEvent| {
|
|
||||||
let artist_name = artist_name.clone();
|
|
||||||
let message = message.clone();
|
|
||||||
let error = error.clone();
|
|
||||||
let fetch = fetch.clone();
|
|
||||||
let artist_id = artist_id.clone();
|
|
||||||
wasm_bindgen_futures::spawn_local(async move {
|
|
||||||
match api::unwatch_artist(artist_id_num).await {
|
|
||||||
Ok(_) => {
|
|
||||||
message.set(Some(format!("Unwatched {artist_name}")));
|
|
||||||
fetch.emit(artist_id);
|
|
||||||
}
|
|
||||||
Err(e) => error.set(Some(e.0)),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})}>
|
|
||||||
{ "Unwatch All" }
|
|
||||||
</button>
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Watch All — prefer enrichment MBID over DB record (import may not have set it)
|
|
||||||
let artist_name = d.artist.name.clone();
|
let artist_name = d.artist.name.clone();
|
||||||
let artist_mbid = d
|
let artist_mbid = d
|
||||||
.artist_info
|
.artist_info
|
||||||
@@ -175,7 +147,43 @@ pub fn artist_page(props: &Props) -> Html {
|
|||||||
{ "Watch All" }
|
{ "Watch All" }
|
||||||
</button>
|
</button>
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
html! {}
|
||||||
|
};
|
||||||
|
|
||||||
|
let unwatch_btn = if is_watched {
|
||||||
|
let artist_id_num = d.artist.id;
|
||||||
|
let artist_name = d.artist.name.clone();
|
||||||
|
let message = message.clone();
|
||||||
|
let error = error.clone();
|
||||||
|
let fetch = fetch.clone();
|
||||||
|
let artist_id = id.clone();
|
||||||
|
html! {
|
||||||
|
<button class="btn btn-sm btn-secondary"
|
||||||
|
onclick={Callback::from(move |_: MouseEvent| {
|
||||||
|
let artist_name = artist_name.clone();
|
||||||
|
let message = message.clone();
|
||||||
|
let error = error.clone();
|
||||||
|
let fetch = fetch.clone();
|
||||||
|
let artist_id = artist_id.clone();
|
||||||
|
wasm_bindgen_futures::spawn_local(async move {
|
||||||
|
match api::unwatch_artist(artist_id_num).await {
|
||||||
|
Ok(_) => {
|
||||||
|
message.set(Some(format!("Unwatched {artist_name}")));
|
||||||
|
fetch.emit(artist_id);
|
||||||
}
|
}
|
||||||
|
Err(e) => error.set(Some(e.0)),
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})}>
|
||||||
|
{ "Unwatch All" }
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
html! {}
|
||||||
|
};
|
||||||
|
|
||||||
|
html! { <> { watch_btn } { unwatch_btn } </> }
|
||||||
};
|
};
|
||||||
|
|
||||||
let monitor_btn = {
|
let monitor_btn = {
|
||||||
@@ -375,8 +383,11 @@ pub fn artist_page(props: &Props) -> Html {
|
|||||||
|
|
||||||
let tc = album.track_count;
|
let tc = album.track_count;
|
||||||
|
|
||||||
// Watch/Unwatch toggle for albums
|
// Watch/Unwatch buttons for albums — show both when partially watched
|
||||||
let watch_btn = if is_unwatched {
|
let is_fully_owned = album.status == "owned";
|
||||||
|
let is_album_watched = album.status != "unwatched";
|
||||||
|
|
||||||
|
let album_watch_btn = {
|
||||||
let artist_name = d.artist.name.clone();
|
let artist_name = d.artist.name.clone();
|
||||||
let album_title = album.title.clone();
|
let album_title = album.title.clone();
|
||||||
let album_mbid = album.mbid.clone();
|
let album_mbid = album.mbid.clone();
|
||||||
@@ -385,7 +396,8 @@ pub fn artist_page(props: &Props) -> Html {
|
|||||||
let fetch = fetch.clone();
|
let fetch = fetch.clone();
|
||||||
let artist_id = id.clone();
|
let artist_id = id.clone();
|
||||||
html! {
|
html! {
|
||||||
<button class="btn btn-sm btn-primary"
|
<button class="btn btn-sm btn-primary btn-fixed"
|
||||||
|
style={if is_fully_owned { "visibility:hidden;" } else { "" }}
|
||||||
onclick={Callback::from(move |_: MouseEvent| {
|
onclick={Callback::from(move |_: MouseEvent| {
|
||||||
let artist_name = artist_name.clone();
|
let artist_name = artist_name.clone();
|
||||||
let album_title = album_title.clone();
|
let album_title = album_title.clone();
|
||||||
@@ -410,7 +422,9 @@ pub fn artist_page(props: &Props) -> Html {
|
|||||||
{ "Watch" }
|
{ "Watch" }
|
||||||
</button>
|
</button>
|
||||||
}
|
}
|
||||||
} else {
|
};
|
||||||
|
|
||||||
|
let album_unwatch_btn = {
|
||||||
let album_title = album.title.clone();
|
let album_title = album.title.clone();
|
||||||
let album_mbid = album.mbid.clone();
|
let album_mbid = album.mbid.clone();
|
||||||
let message = message.clone();
|
let message = message.clone();
|
||||||
@@ -418,7 +432,8 @@ pub fn artist_page(props: &Props) -> Html {
|
|||||||
let fetch = fetch.clone();
|
let fetch = fetch.clone();
|
||||||
let artist_id = id.clone();
|
let artist_id = id.clone();
|
||||||
html! {
|
html! {
|
||||||
<button class="btn btn-sm btn-secondary"
|
<button class="btn btn-sm btn-secondary btn-fixed"
|
||||||
|
style={if !is_album_watched { "visibility:hidden;" } else { "" }}
|
||||||
onclick={Callback::from(move |_: MouseEvent| {
|
onclick={Callback::from(move |_: MouseEvent| {
|
||||||
let album_title = album_title.clone();
|
let album_title = album_title.clone();
|
||||||
let album_mbid = album_mbid.clone();
|
let album_mbid = album_mbid.clone();
|
||||||
@@ -441,6 +456,8 @@ pub fn artist_page(props: &Props) -> Html {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let watch_btn = html! { <span style="display:inline-flex;gap:0.5rem;">{ album_watch_btn } { album_unwatch_btn }</span> };
|
||||||
|
|
||||||
html! {
|
html! {
|
||||||
<tr style={row_style}>
|
<tr style={row_style}>
|
||||||
<td>
|
<td>
|
||||||
|
|||||||
@@ -64,9 +64,16 @@ pub fn library_page() -> Html {
|
|||||||
<tbody>
|
<tbody>
|
||||||
{ for artists.iter().map(|a| {
|
{ for artists.iter().map(|a| {
|
||||||
let artist_id = a.id;
|
let artist_id = a.id;
|
||||||
|
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 error = error.clone();
|
||||||
let fetch = fetch_artists.clone();
|
let fetch = fetch_artists.clone();
|
||||||
let on_remove = Callback::from(move |_: MouseEvent| {
|
Callback::from(move |_: MouseEvent| {
|
||||||
let error = error.clone();
|
let error = error.clone();
|
||||||
let fetch = fetch.clone();
|
let fetch = fetch.clone();
|
||||||
wasm_bindgen_futures::spawn_local(async move {
|
wasm_bindgen_futures::spawn_local(async move {
|
||||||
@@ -75,7 +82,58 @@ pub fn library_page() -> Html {
|
|||||||
Err(e) => error.set(Some(e.0)),
|
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! {
|
html! {
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
@@ -116,8 +174,22 @@ pub fn library_page() -> Html {
|
|||||||
{ a.total_items }
|
{ a.total_items }
|
||||||
}
|
}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td class="actions">
|
||||||
<button class="btn btn-sm btn-danger" onclick={on_remove}>
|
<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" }
|
{ "Remove" }
|
||||||
</button>
|
</button>
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
@@ -248,6 +248,8 @@ tr:hover { background: var(--bg-card); }
|
|||||||
.btn-danger { background: var(--danger); color: white; }
|
.btn-danger { background: var(--danger); color: white; }
|
||||||
.btn-secondary { background: var(--bg-card); color: var(--text-primary); border: 1px solid var(--border); }
|
.btn-secondary { background: var(--bg-card); color: var(--text-primary); border: 1px solid var(--border); }
|
||||||
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.8rem; }
|
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.8rem; }
|
||||||
|
.btn-fixed { min-width: 5.5rem; text-align: center; }
|
||||||
|
.btn-lib { min-width: 4.5rem; text-align: center; padding-left: 0.25rem; padding-right: 0.25rem; }
|
||||||
|
|
||||||
/* Forms */
|
/* Forms */
|
||||||
input, select {
|
input, select {
|
||||||
|
|||||||
@@ -95,9 +95,11 @@ async fn list_artists(
|
|||||||
auth::require_auth(&session)?;
|
auth::require_auth(&session)?;
|
||||||
let artists = queries::artists::list(state.db.conn(), query.limit, query.offset).await?;
|
let artists = queries::artists::list(state.db.conn(), query.limit, query.offset).await?;
|
||||||
|
|
||||||
|
let wanted = queries::wanted::list(state.db.conn(), None, None).await?;
|
||||||
|
|
||||||
let mut items: Vec<ArtistListItem> = Vec::new();
|
let mut items: Vec<ArtistListItem> = Vec::new();
|
||||||
for a in &artists {
|
for a in &artists {
|
||||||
// Check if we have cached artist-level totals from a prior detail page load
|
// Get total_items from enrichment cache (total available tracks from MB)
|
||||||
let cache_key = format!("artist_totals:{}", a.id);
|
let cache_key = format!("artist_totals:{}", a.id);
|
||||||
let cached_totals: Option<(u32, u32, u32)> =
|
let cached_totals: Option<(u32, u32, u32)> =
|
||||||
if let Ok(Some(json)) = queries::cache::get(state.db.conn(), &cache_key).await {
|
if let Ok(Some(json)) = queries::cache::get(state.db.conn(), &cache_key).await {
|
||||||
@@ -107,12 +109,20 @@ async fn list_artists(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let enriched = cached_totals.is_some();
|
let enriched = cached_totals.is_some();
|
||||||
let (total_watched, total_owned, total_items) =
|
let total_items = cached_totals
|
||||||
if let Some((avail, watched, owned)) = cached_totals {
|
.map(|(avail, _, _)| avail as usize)
|
||||||
(watched as usize, owned as usize, avail as usize)
|
.unwrap_or(0);
|
||||||
} else {
|
|
||||||
(0, 0, 0)
|
// Compute watched/owned live from wanted_items (always current)
|
||||||
};
|
let artist_wanted: Vec<_> = wanted
|
||||||
|
.iter()
|
||||||
|
.filter(|w| w.artist_id == Some(a.id))
|
||||||
|
.collect();
|
||||||
|
let total_watched = artist_wanted.len();
|
||||||
|
let total_owned = artist_wanted
|
||||||
|
.iter()
|
||||||
|
.filter(|w| w.status == WantedStatus::Owned)
|
||||||
|
.count();
|
||||||
|
|
||||||
items.push(ArtistListItem {
|
items.push(ArtistListItem {
|
||||||
id: a.id,
|
id: a.id,
|
||||||
|
|||||||
Reference in New Issue
Block a user