about summary refs log tree commit diff
path: root/frontend
diff options
context:
space:
mode:
authorBaitinq <manuelpalenzuelamerino@gmail.com>2022-10-27 17:32:33 +0200
committerBaitinq <manuelpalenzuelamerino@gmail.com>2022-10-27 17:32:47 +0200
commit6b3c3179e0fda27cf78f70d93a69a8b4a7049545 (patch)
tree16a16f2f58d65a68b702ea8de92387a03884ffb8 /frontend
parentFrontend: Use display_results() function for rendering CrawledResources (diff)
downloadOSSE-6b3c3179e0fda27cf78f70d93a69a8b4a7049545.tar.gz
OSSE-6b3c3179e0fda27cf78f70d93a69a8b4a7049545.tar.bz2
OSSE-6b3c3179e0fda27cf78f70d93a69a8b4a7049545.zip
Fronted: Order search results by priority
We do this by implementing the PartialOrd and Ord traits into the
CrawledResource struct and then using Itertools::sorted() on the display
iterator.
Diffstat (limited to 'frontend')
-rw-r--r--frontend/Cargo.toml3
-rw-r--r--frontend/src/main.rs18
2 files changed, 19 insertions, 2 deletions
diff --git a/frontend/Cargo.toml b/frontend/Cargo.toml
index c1be331..106b818 100644
--- a/frontend/Cargo.toml
+++ b/frontend/Cargo.toml
@@ -12,4 +12,5 @@ web-sys = "0.3.60"
 wasm-bindgen = "0.2.83"
 gloo-net = "0.2"
 serde = { version = "1.0", features = ["derive", "rc"] }
-wasm-bindgen-futures = "0.4"
\ No newline at end of file
+wasm-bindgen-futures = "0.4"
+itertools = "0.10.5"
diff --git a/frontend/src/main.rs b/frontend/src/main.rs
index fd28d89..0195a88 100644
--- a/frontend/src/main.rs
+++ b/frontend/src/main.rs
@@ -1,6 +1,8 @@
 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::*;
@@ -22,6 +24,19 @@ impl PartialEq for CrawledResource {
     }
 }
 impl Eq for CrawledResource {}
+
+impl PartialOrd for CrawledResource {
+    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+        Some(self.cmp(other))
+    }
+}
+
+impl Ord for CrawledResource {
+    fn cmp(&self, other: &Self) -> Ordering {
+        self.priority.cmp(&other.priority)
+    }
+}
+
 impl Hash for CrawledResource {
     fn hash<H: Hasher>(&self, state: &mut H) {
         self.url.hash(state);
@@ -44,7 +59,8 @@ fn osse() -> Html {
 
     let display_results = |results: &Vec<CrawledResource>| -> Html {
         results
-            .into_iter()
+            .iter()
+            .sorted()
             .map(|r| {
                 html! {
                     <div key={r.url.to_owned()}>