Added the import/cleanup functionality

This commit is contained in:
Connor Johnstone
2026-03-24 15:58:14 -04:00
parent 1431cd2fbc
commit 823ef15022
11 changed files with 392 additions and 27 deletions

View File

@@ -10,16 +10,25 @@ pub fn library_page() -> Html {
let artists = use_state(|| None::<Vec<ArtistListItem>>);
let error = use_state(|| None::<String>);
{
let fetch_artists = {
let artists = artists.clone();
let error = error.clone();
use_effect_with((), move |_| {
Callback::from(move |_: ()| {
let artists = artists.clone();
let error = error.clone();
wasm_bindgen_futures::spawn_local(async move {
match api::list_artists(200, 0).await {
Ok(a) => artists.set(Some(a)),
Err(e) => error.set(Some(e.0)),
}
});
})
};
{
let fetch = fetch_artists.clone();
use_effect_with((), move |_| {
fetch.emit(());
});
}
@@ -49,10 +58,25 @@ pub fn library_page() -> Html {
<th>{ "Owned" }</th>
<th>{ "Watched" }</th>
<th>{ "Tracks" }</th>
<th></th>
</tr>
</thead>
<tbody>
{ for artists.iter().map(|a| html! {
{ 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 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)),
}
});
});
html! {
<tr>
<td>
<Link<Route> to={Route::Artist { id: a.id.to_string() }}>
@@ -90,7 +114,13 @@ pub fn library_page() -> Html {
{ a.total_items }
}
</td>
<td>
<button class="btn btn-sm btn-danger" onclick={on_remove}>
{ "Remove" }
</button>
</td>
</tr>
}
})}
</tbody>
</table>