Some checks failed
Push Workflows / docs (push) Successful in 1m35s
Push Workflows / rustfmt (push) Successful in 11s
Push Workflows / clippy (push) Failing after 58s
Push Workflows / leptos-test (push) Successful in 3m4s
Push Workflows / test (push) Successful in 3m22s
Push Workflows / build (push) Successful in 4m43s
Push Workflows / docker-build (push) Failing after 14m42s
Push Workflows / nix-build (push) Successful in 17m22s
63 lines
2.2 KiB
Rust
63 lines
2.2 KiB
Rust
use crate::api::artists::add_artist;
|
|
use leptos::leptos_dom::log;
|
|
use leptos::prelude::*;
|
|
use leptos::task::spawn_local;
|
|
use leptos_icons::*;
|
|
|
|
#[component]
|
|
pub fn AddArtistBtn(add_artist_open: RwSignal<bool>) -> impl IntoView {
|
|
let open_dialog = move |_| {
|
|
add_artist_open.set(true);
|
|
};
|
|
view! {
|
|
<button class="add-artist-btn add-btns" on:click=open_dialog>
|
|
Add Artist
|
|
</button>
|
|
}
|
|
}
|
|
#[component]
|
|
pub fn AddArtist(open: RwSignal<bool>) -> impl IntoView {
|
|
let artist_name = RwSignal::new("".to_string());
|
|
|
|
let close_dialog = move |ev: leptos::ev::MouseEvent| {
|
|
ev.prevent_default();
|
|
open.set(false);
|
|
};
|
|
let on_add_artist = move |ev: leptos::ev::SubmitEvent| {
|
|
ev.prevent_default();
|
|
let artist_name_clone = artist_name.get();
|
|
spawn_local(async move {
|
|
let add_artist_result = add_artist(artist_name_clone).await;
|
|
if let Err(err) = add_artist_result {
|
|
log!("Error adding artist: {:?}", err);
|
|
} else if let Ok(artist) = add_artist_result {
|
|
log!("Added artist: {:?}", artist);
|
|
artist_name.set("".to_string());
|
|
}
|
|
});
|
|
};
|
|
|
|
view! {
|
|
<Show when=open fallback=move|| view!{}>
|
|
<div class="add-artist-container">
|
|
<div class="upload-header">
|
|
<h1>Add Artist</h1>
|
|
</div>
|
|
<div class="close-button" on:click=close_dialog><Icon icon={icondata::IoClose} /></div>
|
|
<form class="create-artist-form" on:submit=on_add_artist>
|
|
<div class="input-bx">
|
|
<input type="text" name="title" required class="text-input"
|
|
prop:value=artist_name
|
|
on:input=move |ev: leptos::ev::Event| {
|
|
artist_name.set(event_target_value(&ev));
|
|
}
|
|
/>
|
|
<span>Artist Name</span>
|
|
</div>
|
|
<button type="submit" class="upload-button">Add</button>
|
|
</form>
|
|
</div>
|
|
</Show>
|
|
}
|
|
}
|