diff options
author | Baitinq <manuelpalenzuelamerino@gmail.com> | 2022-10-28 11:11:57 +0200 |
---|---|---|
committer | Baitinq <manuelpalenzuelamerino@gmail.com> | 2022-10-28 11:11:59 +0200 |
commit | 87c53ef747935fe47602d0792bf8f5202b3cc19b (patch) | |
tree | 12e8a7f11170b1c88f725b771107905cd58fe8eb /frontend | |
parent | Misc: Add TODOs (diff) | |
download | OSSE-87c53ef747935fe47602d0792bf8f5202b3cc19b.tar.gz OSSE-87c53ef747935fe47602d0792bf8f5202b3cc19b.tar.bz2 OSSE-87c53ef747935fe47602d0792bf8f5202b3cc19b.zip |
Frontend: Make the results state Optional
We now return "No result!" if the user has actually searched for something and no results were found.
Diffstat (limited to 'frontend')
-rw-r--r-- | frontend/src/main.rs | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/frontend/src/main.rs b/frontend/src/main.rs index 27c30da..605046d 100644 --- a/frontend/src/main.rs +++ b/frontend/src/main.rs @@ -47,28 +47,40 @@ impl Hash for CrawledResource { #[derive(Debug, Clone)] struct State { pub search_query: String, - pub results: Vec<CrawledResource>, //TODO: some loading? + pub results: Option<Vec<CrawledResource>>, //TODO: some loading? } #[function_component(OSSE)] fn osse() -> Html { let state = use_state(|| State { search_query: "".to_string(), - results: vec![], + results: None, }); - let display_results = |results: &Vec<CrawledResource>| -> Html { - results - .iter() - .sorted() - .map(|r| { - html! { - <div key={r.url.to_owned()}> - <a href={r.url.to_owned()}>{r.url.to_owned()}{"--"}{r.priority}</a> - </div> - } - }) - .collect::<Html>() + let display_results = |maybe_results: &Option<Vec<CrawledResource>>| -> Html { + let maybe_results = maybe_results.as_ref(); + if maybe_results.is_none() { + return html! {}; + } + + let results = maybe_results.unwrap(); + if !results.is_empty() { + results + .iter() + .sorted() + .map(|r| { + html! { + <div key={r.url.to_owned()}> + <a href={r.url.to_owned()}>{r.url.to_owned()}{"--"}{r.priority}</a> + </div> + } + }) + .collect::<Html>() + } else { + html! { + <p>{"No results!"}</p> + } + } }; let search_query_changed = { @@ -107,7 +119,7 @@ fn osse() -> Html { Ok(json) => json, }; - state.results = fetched_json; + state.results = Some(fetched_json); cloned_state.set(state); }); |