diff --git a/server/src/lib.rs b/server/src/lib.rs index d935d9e..ac854af 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -27,7 +27,6 @@ use lol_html::{ use maplit::{hashmap, hashset}; use regex::Regex; use reqwest::StatusCode; -use rocket::response::status; use scraper::{Html, Selector}; use sqlx::types::time::PrimitiveDateTime; use thiserror::Error; diff --git a/web/src/view/mod.rs b/web/src/view/mod.rs index 242f360..2b88325 100644 --- a/web/src/view/mod.rs +++ b/web/src/view/mod.rs @@ -177,7 +177,7 @@ fn search_results( span![C!["text-xs"], pretty_authors(&r.authors)], div![ C!["flex", "flex-wrap", "justify-between"], - span![tags_chiclet(&tags, true)], + span![tags_chiclet(&tags)], span![C!["text-sm"], datetime] ] ] @@ -197,7 +197,7 @@ fn set_title(title: &str) { } // TODO: unifiy tags_chiclet, removable_tags_chiclet, and tags inside news_post() -fn tags_chiclet(tags: &[String], is_mobile: bool) -> impl Iterator> + '_ { +fn tags_chiclet(tags: &[String]) -> impl Iterator> + '_ { tags.iter().map(move |tag| { let hex = compute_color(tag); let style = style! {St::BackgroundColor=>hex}; @@ -213,11 +213,7 @@ fn tags_chiclet(tags: &[String], is_mobile: bool) -> impl Iterator( - thread_id: &'a str, - tags: &'a [String], - is_mobile: bool, -) -> Node { +fn removable_tags_chiclet<'a>(thread_id: &'a str, tags: &'a [String]) -> Node { div![ C!["flex"], tags.iter().map(move |tag| { @@ -309,131 +305,6 @@ fn human_age(timestamp: i64) -> String { datetime } -fn view_search_results( - query: &str, - results: &[FrontPageQuerySearchNodes], - count: usize, - pager: &FrontPageQuerySearchPageInfo, - selected_threads: &HashSet, -) -> Node { - if query.is_empty() { - set_title("all mail"); - } else { - set_title(query); - } - let show_bulk_edit = !selected_threads.is_empty(); - let all_checked = selected_threads.len() == results.len(); - let partially_checked = !selected_threads.is_empty() && !all_checked; - let rows = results.iter().map(|r| { - let tid = r.thread.clone(); - let check_tid = r.thread.clone(); - let datetime = human_age(r.timestamp as i64); - let unread_idx = r.tags.iter().position(|e| e == &"unread"); - let mut tags = r.tags.clone(); - if let Some(idx) = unread_idx { - tags.remove(idx); - }; - let subject = if r.subject.is_empty() { - "(no subject)" - } else { - &r.subject - }; - tr![ - IF!(unread_idx.is_some() => C!["NOTPORTED","unread"]), - td![label![ - C!["NOTPORTED", "b-checkbox", "checkbox"], - input![attrs! { - At::Type=>"checkbox", - At::Checked=>selected_threads.contains(&tid).as_at_value(), - }], - span![C!["NOTPORTED", "check"]], - ev(Ev::Input, move |e| { - if let Some(input) = e - .target() - .as_ref() - .expect("failed to get reference to target") - .dyn_ref::() - { - if input.checked() { - Msg::SelectionAddThread(check_tid) - } else { - Msg::SelectionRemoveThread(check_tid) - } - } else { - Msg::Noop - } - }), - ]], - td![ - C!["NOTPORTED", "from", format!("corpus-{:?} ", r.corpus)], - a![ - C!["NOTPORTED", "has-text-light", "text"], - attrs! { - At::Href => urls::thread(&tid) - }, - pretty_authors(&r.authors), - IF!(r.total>1 => small![" ", r.total.to_string()]), - ] - ], - td![ - C!["NOTPORTED", "subject"], - a![ - tags_chiclet(&tags, false), - " ", - C!["NOTPORTED", "has-text-light", "text", "subject-link"], - attrs! { - At::Href => urls::thread(&tid) - }, - &subject, - ] - ], - td![ - C!["NOTPORTED", "date"], - a![ - C!["NOTPORTED", "has-text-light", "text"], - attrs! { - At::Href => urls::thread(&tid) - }, - datetime - ] - ] - ] - }); - return h1!["HELLO"]; - div![ - C!["flex"], - search_toolbar(count, pager, show_bulk_edit), - div![ - thead![tr![ - th![ - C!["NOTPORTED", "edit"], - label![ - C!["NOTPORTED", "b-checkbox", "checkbox"], - input![ - IF!(partially_checked => C!["NOTPORTED","is-indeterminate"]), - attrs! { - At::Type=>"checkbox", - At::Checked=>all_checked.as_at_value(), - } - ], - span![C!["NOTPORTED", "check"]], - ev(Ev::Click, move |_| if all_checked { - Msg::SelectionSetNone - } else { - Msg::SelectionSetAll - }) - ] - ], - th![C!["NOTPORTED", "from"], "From"], - th![C!["NOTPORTED", "subject"], "Subject"], - th![C!["NOTPORTED", "date"], "Date"] - ]], - tbody![rows] - ], - search_toolbar(count, pager, show_bulk_edit) - ] -} - fn search_toolbar( count: usize, pager: &FrontPageQuerySearchPageInfo, @@ -909,7 +780,7 @@ fn thread( div![ C!["p-4", "lg:p-0"], h3![C!["text-xl"], subject], - span![removable_tags_chiclet(&thread.thread_id, &tags, false)], + span![removable_tags_chiclet(&thread.thread_id, &tags)], div![ C!["pt-4", "gap-2", "flex", "justify-around"], div![ @@ -1158,7 +1029,7 @@ fn news_post(post: &ShowThreadQueryThreadOnNewsPost, content_el: &ElRef Node { + fn tag(tag: String) -> Node { let hex = compute_color(&tag); let style = style! {St::BackgroundColor=>hex}; let attrs = attrs! { @@ -1183,7 +1054,7 @@ fn news_post(post: &ShowThreadQueryThreadOnNewsPost, content_el: &ElRef