From 0a0abdac04e89ce93b26061fceffd0832bf6b6ed Mon Sep 17 00:00:00 2001 From: Baitinq Date: Wed, 26 Oct 2022 13:05:05 +0200 Subject: Frontend: Add results field to the state and set dummy results --- frontend/src/main.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) (limited to 'frontend') diff --git a/frontend/src/main.rs b/frontend/src/main.rs index 30ec0ef..e09b259 100644 --- a/frontend/src/main.rs +++ b/frontend/src/main.rs @@ -1,18 +1,43 @@ use gloo::console::log; -use std::ops::Deref; +use std::hash::{Hash, Hasher}; +use std::{ops::Deref, sync::Arc}; use wasm_bindgen::*; use web_sys::{EventTarget, HtmlInputElement}; use yew::prelude::*; +//TODO: we should import this from the indexer +#[derive(Debug, Clone)] +struct CrawledResource { + url: String, + priority: u32, //how do we even calculate this + word: Arc, +} + +//We implement PartialEq, Eq and Hash to ignore the priority field. +impl PartialEq for CrawledResource { + fn eq(&self, other: &Self) -> bool { + self.url == other.url && self.word == other.word + } +} +impl Eq for CrawledResource {} +impl Hash for CrawledResource { + fn hash(&self, state: &mut H) { + self.url.hash(state); + self.word.hash(state); + } +} + #[derive(Debug, Clone)] struct State { pub search_query: String, + pub results: Vec, //TODO: some loading? } #[function_component(OSSE)] fn osse() -> Html { let state = use_state(|| State { search_query: "".to_string(), + results: vec![], }); let cloned_state = state.clone(); @@ -33,6 +58,18 @@ fn osse() -> Html { let mut state = cloned_state.deref().clone(); log!("Submit:{}", state.search_query); state.search_query = "".to_string(); + state.results = vec![ + CrawledResource { + url: "http://example.com".to_string(), + priority: 12, + word: Arc::new("example".to_string()), + }, + CrawledResource { + url: "http://test.com".to_string(), + priority: 17, + word: Arc::new("test".to_string()), + }, + ]; cloned_state.set(state); }); @@ -52,7 +89,7 @@ fn osse() -> Html {
- {"OSSE"} + {"OSSE"}

{"Your favorite independent search engine."}

@@ -60,6 +97,13 @@ fn osse() -> Html {
+
+ {curr_state.results.into_iter().map(|r| { + html!{ +
{ format!("Result: {:?}!", r) }
+ } + }).collect::()} +
-- cgit 1.4.1