about summary refs log tree commit diff
path: root/frontend
diff options
context:
space:
mode:
authorBaitinq <manuelpalenzuelamerino@gmail.com>2022-10-30 12:59:46 +0100
committerBaitinq <manuelpalenzuelamerino@gmail.com>2022-10-30 12:59:46 +0100
commit620d82cc3910d21940e9cc737900440be3b0ced4 (patch)
tree82f8b4b9e93deed5f72a61c5784d6fff5c5bc971 /frontend
parentFrontend: Add props to the OSSE Component (diff)
downloadOSSE-620d82cc3910d21940e9cc737900440be3b0ced4.tar.gz
OSSE-620d82cc3910d21940e9cc737900440be3b0ced4.tar.bz2
OSSE-620d82cc3910d21940e9cc737900440be3b0ced4.zip
Misc: Add local lib crate to share common structs
Diffstat (limited to 'frontend')
-rw-r--r--frontend/Cargo.toml1
-rw-r--r--frontend/src/main.rs45
2 files changed, 3 insertions, 43 deletions
diff --git a/frontend/Cargo.toml b/frontend/Cargo.toml
index 23acba2..b528d2b 100644
--- a/frontend/Cargo.toml
+++ b/frontend/Cargo.toml
@@ -15,3 +15,4 @@ serde = { version = "1.0", features = ["derive", "rc"] }
 wasm-bindgen-futures = "0.4"
 itertools = "0.10.5"
 scraper = "0.12.0"
+lib = { path = "../lib" }
\ No newline at end of file
diff --git a/frontend/src/main.rs b/frontend/src/main.rs
index 2052a89..b83ccdd 100644
--- a/frontend/src/main.rs
+++ b/frontend/src/main.rs
@@ -1,50 +1,9 @@
-use gloo::console::log;
 use gloo_net::http::Request;
 use itertools::Itertools;
-use serde::Deserialize;
-use std::cmp::Ordering;
-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, Deserialize)]
-pub struct IndexedResource {
-    url: String,
-    title: String,
-    description: String,
-    priority: u32,
-    word: Arc<String>,
-}
-
-//We implement PartialEq, Eq and Hash to ignore the priority field.
-impl PartialEq for IndexedResource {
-    fn eq(&self, other: &Self) -> bool {
-        self.url == other.url && self.word == other.word
-    }
-}
-impl Eq for IndexedResource {}
-
-impl PartialOrd for IndexedResource {
-    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
-        Some(self.cmp(other))
-    }
-}
-
-impl Ord for IndexedResource {
-    fn cmp(&self, other: &Self) -> Ordering {
-        self.priority.cmp(&other.priority).reverse()
-    }
-}
-
-impl Hash for IndexedResource {
-    fn hash<H: Hasher>(&self, state: &mut H) {
-        self.url.hash(state);
-        self.word.hash(state);
-    }
-}
+use lib::lib::*;
 
 #[derive(Properties, Clone, PartialEq, Eq)]
 pub struct ResultComponentProps {
@@ -65,7 +24,7 @@ pub struct OSSE {
     pub results: Option<Vec<IndexedResource>>, //TODO: some loading?
 }
 
-#[derive(Properties, PartialEq)]
+#[derive(Properties, PartialEq, Eq)]
 pub struct OSSEProps {
     pub api_endpoint: String,
 }