From d73a114d35ac76f0037b93b9aecb8299dc40a8e9 Mon Sep 17 00:00:00 2001 From: ecco257 Date: Fri, 6 Dec 2024 19:37:48 -0500 Subject: [PATCH] Simplify search results and make more efficient using tokio join through general search server function --- src/components/search.rs | 51 ++++++++++------------------------------ src/models.rs | 2 +- 2 files changed, 13 insertions(+), 40 deletions(-) diff --git a/src/components/search.rs b/src/components/search.rs index ead324f..46992bb 100644 --- a/src/components/search.rs +++ b/src/components/search.rs @@ -1,8 +1,6 @@ use html::Li; use leptos::*; -use crate::search::search_albums; -use crate::search::search_artists; -use crate::search::search_songs; +use crate::search::search; use crate::song::Song; use crate::models::Album; use crate::models::Artist; @@ -20,9 +18,7 @@ pub fn Search() -> impl IntoView { let status = GlobalState::play_status(); let search_query = create_rw_signal(String::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_results = create_rw_signal((Vec::<(Album, f32)>::new(), Vec::<(Artist, f32)>::new(), Vec::<(Song, f32)>::new())); let search_limit = 10; let on_input = move |e: Event| { @@ -32,36 +28,16 @@ pub fn Search() -> impl IntoView { spawn_local(async move { log!("Searching for: {:?}", search_query.get_untracked()); - 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; + let results = search(search_query.get_untracked(), search_limit).await; - match albums { - Ok(albums) => { - album_search_results.set(albums); + match results { + Ok((albums, artists, songs)) => { + search_results.set((albums, artists, songs)); } 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); - } - } }); }; @@ -91,10 +67,9 @@ pub fn Search() -> impl IntoView {
// Display 3 columns of search results: songs, albums, and artists