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
44
45
46
47
48
49
50
|
use super::layout::Layout;
use crate::{
frontend::pages::MyResult,
library::{LibDirectory, LibItem, LibNode},
AppState,
};
use actix_web::{get, web, Responder};
use actix_web_lab::respond::Html;
use log::debug;
use markup::Render;
use std::{ops::Deref, sync::Arc};
#[get("/library/{path:.*}")]
pub async fn page_library_node(
state: web::Data<AppState>,
params: web::Path<(String,)>,
) -> MyResult<impl Responder> {
debug!("request: {:?}", params.0);
let node = state.library.nested(¶ms.0)?;
let mut out = String::new();
match node.deref() {
LibNode::Directory(dir) => Layout {
title: format!("{} - Library", node.title()),
main: Directory { dir: dir.clone() },
}
.render(&mut out)?,
LibNode::Item(item) => Layout {
title: "".to_string(),
main: Item { item: item.clone() },
}
.render(&mut out)?,
};
Ok(Html(out))
}
markup::define! {
Directory(dir: Arc<LibDirectory>) {
h1 { @dir.data.name }
ul.directorylisting {
@for el in &dir.child_nodes().unwrap() {
li {
span.title { @el.title() }
}
}
}
}
Item(item: Arc<LibItem>) {
h1 { "thats an item" }
}
}
|