aboutsummaryrefslogtreecommitdiff
path: root/ui/src/search.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ui/src/search.rs')
-rw-r--r--ui/src/search.rs38
1 files changed, 25 insertions, 13 deletions
diff --git a/ui/src/search.rs b/ui/src/search.rs
index 092ad57..f252620 100644
--- a/ui/src/search.rs
+++ b/ui/src/search.rs
@@ -4,28 +4,40 @@
Copyright (C) 2025 metamuffin <metamuffin.org>
*/
+use crate::{
+ Page,
+ locale::{Language, tr, trs},
+ node_card::NodeCard,
+};
+use jellycommon::api::ApiSearchResponse;
+use markup::DynRender;
+
+impl Page for SearchPage<'_> {
+ fn title(&self) -> String {
+ tr(*self.lang, "search.title").to_string()
+ }
+ fn class(&self) -> Option<&'static str> {
+ Some("search")
+ }
+ fn to_render(&self) -> DynRender {
+ markup::new!(@self)
+ }
+}
+
markup::define! {
- SearchPage {
+ SearchPage<'a>(lang: &'a Language, r: Option<ApiSearchResponse>, query: &'a Option<String>) {
h1 { @trs(&lang, "search.title") }
form[action="", method="GET"] {
- input[type="text", name="query", placeholder=&*tr(lang, "search.placeholder"), value=&query];
+ input[type="text", name="query", placeholder=&*tr(**lang, "search.placeholder"), value=&query];
input[type="submit", value="Search"];
}
- @if let Some((count, results, search_dur)) = &results {
+ @if let Some(r) = &r {
h2 { @trs(&lang, "search.results.title") }
- p.stats { @tr(lang, "search.results.stats").replace("{count}", &count.to_string()).replace("{dur}", &format!("{search_dur:?}")) }
- ul.children {@for (node, udata) in results.iter() {
+ p.stats { @tr(**lang, "search.results.stats").replace("{count}", &r.count.to_string()).replace("{dur}", &format!("{:?}", r.duration)) }
+ ul.children {@for (node, udata) in r.results.iter() {
li { @NodeCard { node, udata, lang: &lang } }
}}
// TODO pagination
}
}
}
-
-pub fn search_page() {
- LayoutPage {
- title: tr(lang, "search.title").to_string(),
- class: Some("search"),
- content: SearchPage,
- }
-} \ No newline at end of file