diff --git a/src/components/upload.rs b/src/components/upload.rs index 40c74e1..8e35c4b 100644 --- a/src/components/upload.rs +++ b/src/components/upload.rs @@ -3,6 +3,7 @@ use leptos::*; use leptos_icons::*; use leptos_router::Form; use crate::search::search_artists; +use crate::models::Artist; #[component] pub fn UploadBtn(dialog_open: RwSignal) -> impl IntoView { @@ -22,24 +23,29 @@ pub fn UploadBtn(dialog_open: RwSignal) -> impl IntoView { #[component] pub fn Upload(open: RwSignal) -> impl IntoView { - let (artists_search, set_artists_search) = create_signal("".to_string()); + // Create signals for the artist input and the filtered artists + let (artists, set_artists) = create_signal("".to_string()); let (filtered_artists, set_filtered_artists) = create_signal(vec![]); + let close_dialog = move |ev: leptos::ev::MouseEvent| { ev.prevent_default(); open.set(false); }; - // let click_cancel_bubble = move |ev: leptos::ev::MouseEvent| { - // ev.prevent_default(); - // ev.stop_propagation(); - // }; + // Create a filter function to handle filtering artists let handle_filter = move |ev: leptos::ev::Event| { ev.prevent_default(); - let searchArtist = event_target_value(&ev); - log!("searchArtist: {:?}", searchArtist); - set_artists_search.update(|value| *value = searchArtist); + + let artist_input: String = event_target_value(&ev); + + //Get the artist that we are currently searching for + let mut all_artists: Vec<&str> = artist_input.split(",").collect(); + let search = all_artists.pop().unwrap().to_string(); + + //Update the artist signal with the input + set_artists.update(|value: &mut String| *value = artist_input); spawn_local(async move { - let filter_results = search_artists(artists_search.get_untracked(), 3).await; + let filter_results = search_artists(search, 3).await; if let Err(err) = filter_results { log!("Error filtering artists: {:?}", err); } else if let Ok(artists) = filter_results { @@ -48,7 +54,6 @@ pub fn Upload(open: RwSignal) -> impl IntoView { set_filtered_artists.update(|value| *value = artists); } }) - }; view! { @@ -58,15 +63,13 @@ pub fn Upload(open: RwSignal) -> impl IntoView {

Upload Song

-
Title
-
- + Artists
) -> impl IntoView {
    { move || filtered_artists.get().iter().enumerate().map(|(_index,filtered_artist)| view! { -
    - {filtered_artist.clone().name} -
    + }).collect::>() }
- -
-
Album ID @@ -95,7 +93,6 @@ pub fn Upload(open: RwSignal) -> impl IntoView { Track Number
-
Release @@ -103,15 +100,60 @@ pub fn Upload(open: RwSignal) -> impl IntoView {
-
File
-
} } + +#[component] +pub fn Artist(artist: Artist, artists: ReadSignal, set_artists: WriteSignal, set_filtered: WriteSignal>) -> impl IntoView { + + // Create a function to add an artist to the artist input + let add_artist = move |_| { + //Create an empty string to hold the artist ids + let mut s: String = String::from(""); + //Get the current value of the artist input + let all_artirts: String = artists.get(); + //Split the input into a vector of artists separated by commas + let mut ids: Vec<&str> = all_artirts.split(",").collect(); + //If there is only one artist in the input, get their id equivalent and add it to the string + if ids.len() == 1 { + let value_str = match artist.id.clone() { + Some(v) => v.to_string(), + None => String::from("None"), + }; + s.push_str(&value_str); + s.push_str(","); + set_artists.update(|value| *value = s); + //If there are multiple artists in the input, pop the last artist by string off the vector, + //get their id equivalent, and add it to the string + } else { + ids.pop(); + for id in ids { + s.push_str(id); + s.push_str(","); + } + let value_str = match artist.id.clone() { + Some(v) => v.to_string(), + None => String::from("None"), + }; + s.push_str(&value_str); + s.push_str(","); + set_artists.update(|value| *value = s); + } + //Clear the search results + set_filtered.update(|value| *value = vec![]); + }; + + view! { +
+ {artist.name.clone()} +
+ } +} \ No newline at end of file diff --git a/style/upload.scss b/style/upload.scss index 65f8d6c..b84920b 100644 --- a/style/upload.scss +++ b/style/upload.scss @@ -161,6 +161,11 @@ .artist { border-bottom: 1px solid white; padding: 10px; + cursor: pointer; + transition: 0.3s; + &:hover { + background-color: #7f8fa6; + } } .artist:last-child { border-bottom: none;