aboutsummaryrefslogtreecommitdiff
path: root/server/src/ui/items.rs
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/ui/items.rs')
-rw-r--r--server/src/ui/items.rs45
1 files changed, 26 insertions, 19 deletions
diff --git a/server/src/ui/items.rs b/server/src/ui/items.rs
index 286fc01..b800914 100644
--- a/server/src/ui/items.rs
+++ b/server/src/ui/items.rs
@@ -4,49 +4,56 @@
Copyright (C) 2026 metamuffin <metamuffin.org>
*/
-use crate::{request_info::RequestInfo, ui::error::MyResult, ui_responder::UiResponse};
+use crate::{request_info::RequestInfo, ui::error::MyResult};
use anyhow::anyhow;
use base64::{Engine, prelude::BASE64_URL_SAFE};
use jellycommon::{
- jellyobject::{OBB, Path},
+ jellyobject::{Object, Path},
*,
};
use jellydb::{Filter, Query};
-use rocket::get;
+use jellyui::components::items::Items;
+use rocket::{get, response::content::RawHtml};
#[get("/items?<cont>")]
-pub fn r_items(ri: RequestInfo, cont: Option<&str>) -> MyResult<UiResponse> {
- let cont = cont
+pub fn r_items(ri: RequestInfo, cont: Option<&str>) -> MyResult<RawHtml<String>> {
+ let cont_in = cont
.map(|s| BASE64_URL_SAFE.decode(s))
.transpose()
.map_err(|_| anyhow!("invalid contination token"))?;
- let mut page = OBB::new();
+ let mut items = Vec::new();
+ let mut cont_out = None;
ri.state.database.transaction(&mut |txn| {
let rows = txn
.query(Query {
filter: Filter::Match(Path(vec![NO_KIND.0]), KIND_CHANNEL.into()),
- continuation: cont.clone(),
+ continuation: cont_in.clone(),
..Default::default()
})?
.take(64)
.collect::<Result<Vec<_>, _>>()?;
- let mut list = OBB::new().with(NODELIST_DISPLAYSTYLE, NLSTYLE_GRID);
-
- let mut iterstate = Vec::new();
+ items.clear();
+ cont_out = None;
for (r, is) in rows {
let node = txn.get(r)?.unwrap();
- let nku = OBB::new().with(NKU_NODE, node.as_object()).finish();
- list.push(NODELIST_ITEM, nku.as_object());
- iterstate = is;
+ items.push(node);
+ cont_out = Some(is)
}
- list.push(NODELIST_CONTINUATION, &BASE64_URL_SAFE.encode(iterstate));
-
- page = OBB::new();
- page.push(VIEW_NODE_LIST, list.finish().as_object());
-
Ok(())
})?;
- Ok(ri.respond_ui(page))
+
+ Ok(ri.respond_ui(&Items {
+ ri: &ri.render_info(),
+ items: &items
+ .iter()
+ .map(|node| Nku {
+ node: node.as_object(),
+ userdata: Object::EMPTY,
+ role: None,
+ })
+ .collect::<Vec<_>>(),
+ cont: cont_out.map(|x| BASE64_URL_SAFE.encode(x)),
+ }))
}