aboutsummaryrefslogtreecommitdiff
path: root/ui/src/search.rs
blob: 106913ae50b687373cfe2bfd0cdd370dc0fe8738 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
    This file is part of jellything (https://codeberg.org/metamuffin/jellything)
    which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
    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<'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="submit", value="Search"];
        }
        @if let Some(r) = &r {
            h2 { @trs(&lang, "search.results.title") }
            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
        }
    }
}