From 620d82cc3910d21940e9cc737900440be3b0ced4 Mon Sep 17 00:00:00 2001 From: Baitinq Date: Sun, 30 Oct 2022 12:59:46 +0100 Subject: Misc: Add local lib crate to share common structs --- frontend/Cargo.toml | 1 + frontend/src/main.rs | 45 ++------------------------------------------- 2 files changed, 3 insertions(+), 43 deletions(-) (limited to 'frontend') 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, -} - -//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 { - 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(&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>, //TODO: some loading? } -#[derive(Properties, PartialEq)] +#[derive(Properties, PartialEq, Eq)] pub struct OSSEProps { pub api_endpoint: String, } -- cgit 1.4.1