diff --git a/src/components/search.rs b/src/components/search.rs index 4e98b27..52596a8 100644 --- a/src/components/search.rs +++ b/src/components/search.rs @@ -1,5 +1,8 @@ +use html::Li; use leptos::*; -use crate::search::search; +use crate::search::search_albums; +use crate::search::search_artists; +use crate::search::search_songs; use crate::song::Song; use crate::models::Album; use crate::models::Artist; @@ -17,7 +20,9 @@ pub fn Search() -> impl IntoView { let status = GlobalState::play_status(); let search_query = create_rw_signal(String::new()); - let search_results = create_rw_signal((Vec::<(Album, f32)>::new(), Vec::<(Artist, f32)>::new(), Vec::<(Song, f32)>::new())); + let album_search_results = create_rw_signal(Vec::<(Album, f32)>::new()); + let artist_search_results = create_rw_signal(Vec::<(Artist, f32)>::new()); + let song_search_results = create_rw_signal(Vec::<(Song, f32)>::new()); let search_limit = 10; let on_input = move |e: Event| { @@ -25,26 +30,54 @@ pub fn Search() -> impl IntoView { log!("Search Query: {:?}", search_query.get_untracked()); - if search_query.get_untracked().len() < 3 { - search_results.set((Vec::<(Album, f32)>::new(), Vec::<(Artist, f32)>::new(), Vec::<(Song, f32)>::new())); - return; - } spawn_local(async move { log!("Searching for: {:?}", search_query.get_untracked()); - let results = search(search_query.get_untracked(), search_limit).await; - match results { - Ok((albums, artists, songs)) => { - search_results.set((albums, artists, songs)); - } - Err(err) => { - log!("Error searching: {:?}", err); - } - } + // let results = search(search_query.get_untracked(), search_limit).await; + // match results { + // Ok((albums, artists, songs)) => { + // search_results.set((albums, artists, songs)); + // } + // Err(err) => { + // log!("Error searching: {:?}", err); + // } + // } + let albums = search_albums(search_query.get_untracked(), search_limit).await; + let artists = search_artists(search_query.get_untracked(), search_limit).await; + let songs = search_songs(search_query.get_untracked(), search_limit).await; + + match albums { + Ok(albums) => { + album_search_results.set(albums); + } + Err(err) => { + log!("Error searching albums: {:?}", err); + } + } + + match artists { + Ok(artists) => { + artist_search_results.set(artists); + } + Err(err) => { + log!("Error searching artists: {:?}", err); + } + } + + match songs { + Ok(songs) => { + song_search_results.set(songs); + } + Err(err) => { + log!("Error searching songs: {:?}", err); + } + } }); }; let on_disabled = move |_e: FocusEvent| { - + status.update(|status| { + status.search_active = false; + }); log!("Search Bar Disabled"); }; @@ -65,92 +98,187 @@ pub fn Search() -> impl IntoView {
-
+ + }); + } + + song_list + })} + + + /* { + move || search_results.with(|(albums, artists, songs)| -> (leptos::HtmlElement