aboutsummaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/src/routes/ui/layout.rs6
-rw-r--r--server/src/routes/ui/node.rs41
-rw-r--r--server/src/routes/ui/player.rs1
-rw-r--r--server/src/routes/ui/sort.rs7
-rw-r--r--server/src/routes/ui/style.rs36
5 files changed, 61 insertions, 30 deletions
diff --git a/server/src/routes/ui/layout.rs b/server/src/routes/ui/layout.rs
index 1c47247..cdac09c 100644
--- a/server/src/routes/ui/layout.rs
+++ b/server/src/routes/ui/layout.rs
@@ -27,7 +27,7 @@ use rocket::{
use std::io::Cursor;
markup::define! {
- Layout<'a, Main: Render>(title: String, main: Main, class: Option<&'a str>, session: Option<Session>, show_back: bool) {
+ Layout<'a, Main: Render>(title: String, main: Main, class: Option<&'a str>, session: Option<Session>) {
@markup::doctype()
html {
head {
@@ -37,7 +37,6 @@ markup::define! {
}
body[class=class.unwrap_or("")] {
nav {
- @if *show_back { a[href="javascript:history.back()"] { "<- Back" } } " "
h1 { a[href="/"] { @CONF.brand } } " "
@if let Some(_) = session {
a[href=uri!(r_library_node("library"))] { "My Library" } " "
@@ -80,7 +79,6 @@ pub type DynLayoutPage<'a> = LayoutPage<markup::DynRender<'a>>;
pub struct LayoutPage<T> {
pub title: String,
pub class: Option<&'static str>,
- pub show_back: bool,
pub content: T,
}
@@ -90,7 +88,6 @@ impl Default for LayoutPage<DynRender<'_>> {
class: None,
content: markup::new!(),
title: String::new(),
- show_back: false,
}
}
}
@@ -103,7 +100,6 @@ impl<'r, Main: Render> Responder<'r, 'static> for LayoutPage<Main> {
let session = block_on(req.guard::<Option<Session>>()).unwrap();
let mut out = String::new();
Layout {
- show_back: self.show_back,
main: self.content,
title: self.title,
class: self.class.as_deref(),
diff --git a/server/src/routes/ui/node.rs b/server/src/routes/ui/node.rs
index e4d53e6..bb97146 100644
--- a/server/src/routes/ui/node.rs
+++ b/server/src/routes/ui/node.rs
@@ -72,7 +72,6 @@ pub async fn r_library_node_filter<'a>(
Ok(Either::Left(LayoutPage {
title: node.title.to_string(),
- show_back: true, //- !matches!(node.kind, NodeKind::Collection),
content: markup::new! {
@NodePage { node: &node, id: &id, children: &children, filter: &filter }
},
@@ -82,24 +81,37 @@ pub async fn r_library_node_filter<'a>(
markup::define! {
NodeCard<'a>(id: &'a str, node: &'a NodePublic) {
- @let cls = format!("node card {}", match node.kind {NodeKind::Channel => "aspect-square", NodeKind::Video => "aspect-thumb", NodeKind::Collection => "aspect-land", _ => "aspect-port"});
+ @let cls = format!("node card poster {}", match node.kind {NodeKind::Channel => "aspect-square", NodeKind::Video => "aspect-thumb", NodeKind::Collection => "aspect-land", _ => "aspect-port"});
div[class=cls] {
.poster {
- .inner {
- a[href=uri!(r_library_node(id))] {
- img[src=uri!(r_item_assets(id, AssetRole::Poster, Some(1024)))];
+ a[href=uri!(r_library_node(id))] {
+ img[src=uri!(r_item_assets(id, AssetRole::Poster, Some(1024)))];
+ }
+ @if matches!(node.kind, NodeKind::Collection | NodeKind::Channel) {
+ .cardhover.open {
+ a[href=&uri!(r_library_node(id))] { "Open" }
+ @Props { node }
}
- div.details {
- h3 { @node.title }
+ } else {
+ .cardhover.item {
+ a.play[href=&uri!(r_player(id, PlayerConfig::default()))] { "▶" }
@Props { node }
- p.description { @node.description }
- @if matches!(node.kind, NodeKind::Collection | NodeKind::Channel) {
- a[href=&uri!(r_library_node(id))] { "Open" }
- } else {
- a.play[href=&uri!(r_player(id, PlayerConfig::default()))] { "Watch now" }
- }
}
}
+ // .inner {
+ // a[href=uri!(r_library_node(id))] {
+ // img[src=uri!(r_item_assets(id, AssetRole::Poster, Some(1024)))];
+ // }
+ // div.details {
+ // h3 { @node.title }
+ // p.descriptioüwn { @node.description }
+ // @if matches!(node.kind, NodeKind::Collection | NodeKind::Channel) {
+ // a[href=&uri!(r_library_node(id))] { "Open" }
+ // } else {
+ // a.play[href=&uri!(r_player(id, PlayerConfig::default()))] { "Watch now" }
+ // }
+ // }
+ // }
}
div.title {
a[href=uri!(r_library_node(id))] {
@@ -167,6 +179,9 @@ markup::define! {
Rating::Imdb => { "IMDb Rating: " @value }
} }
}
+ @if let Some(d) = &node.release_date {
+ p { "Released " @d.to_rfc2822() }
+ }
}
}
}
diff --git a/server/src/routes/ui/player.rs b/server/src/routes/ui/player.rs
index 4a636e6..d3a3342 100644
--- a/server/src/routes/ui/player.rs
+++ b/server/src/routes/ui/player.rs
@@ -70,7 +70,6 @@ pub fn r_player<'a>(
}
@conf
},
- show_back: true,
..Default::default()
})
}
diff --git a/server/src/routes/ui/sort.rs b/server/src/routes/ui/sort.rs
index da5061d..e1af9d5 100644
--- a/server/src/routes/ui/sort.rs
+++ b/server/src/routes/ui/sort.rs
@@ -53,11 +53,16 @@ pub fn filter_and_sort_nodes(f: &NodeFilterSort, nodes: &mut Vec<(String, NodePu
if let Some(kind) = &f.filter_kind {
o &= kind.contains(&node.kind)
}
+ if let Some(SortProperty::ReleaseDate) = &f.sort_by {
+ o &= node.release_date.is_some()
+ }
o
});
if let Some(sort_prop) = &f.sort_by {
match sort_prop {
- SortProperty::ReleaseDate => nodes.sort_by_key(|(_, _n)| 0), // TODO
+ SortProperty::ReleaseDate => {
+ nodes.sort_by_key(|(_, n)| n.release_date.expect("asserted above"))
+ }
SortProperty::Title => nodes.sort_by(|(_, a), (_, b)| a.title.cmp(&b.title)),
SortProperty::RatingRottenTomatoes => nodes.sort_by_cached_key(|(_, n)| {
SortAnyway(*n.ratings.get(&Rating::RottenTomatoes).unwrap_or(&0.))
diff --git a/server/src/routes/ui/style.rs b/server/src/routes/ui/style.rs
index 1f92690..bdaddd2 100644
--- a/server/src/routes/ui/style.rs
+++ b/server/src/routes/ui/style.rs
@@ -4,7 +4,11 @@
Copyright (C) 2023 metamuffin <metamuffin.org>
Copyright (C) 2023 tpart
*/
-use rocket::{get, http::ContentType};
+use rocket::{
+ get,
+ http::{ContentType, Header},
+ response::Responder,
+};
macro_rules! concat_files {
([$base: expr], $($files:literal),*) => {{
@@ -37,10 +41,22 @@ fn css_bundle() -> String {
"nodepage.css",
"nodecard.css",
"js-player.css",
+ "js-transition.css",
"forms.css"
)
}
+pub struct CachedAsset<T>(pub T);
+impl<'r, 'o: 'r, T: Responder<'r, 'o>> Responder<'r, 'o> for CachedAsset<T> {
+ fn respond_to(self, request: &'r rocket::Request<'_>) -> rocket::response::Result<'o> {
+ let mut res = self.0.respond_to(request)?;
+ if cfg!(not(debug_assertions)) {
+ res.set_header(Header::new("cache-control", "max-age=86400"));
+ }
+ Ok(res)
+ }
+}
+
fn js_bundle() -> String {
concat_files!([env!("OUT_DIR")], "bundle.js")
}
@@ -49,23 +65,23 @@ fn js_bundle_map() -> String {
}
#[get("/assets/style.css")]
-pub fn r_assets_style() -> (ContentType, String) {
- (ContentType::CSS, css_bundle())
+pub fn r_assets_style() -> CachedAsset<(ContentType, String)> {
+ CachedAsset((ContentType::CSS, css_bundle()))
}
#[get("/assets/cantarell.woff2")]
-pub fn r_assets_font() -> (ContentType, &'static [u8]) {
- (
+pub fn r_assets_font() -> CachedAsset<(ContentType, &'static [u8])> {
+ CachedAsset((
ContentType::WOFF2,
include_bytes!("../../../../web/cantarell.woff2"),
- )
+ ))
}
#[get("/assets/bundle.js")]
-pub fn r_assets_js() -> (ContentType, String) {
- (ContentType::JavaScript, js_bundle())
+pub fn r_assets_js() -> CachedAsset<(ContentType, String)> {
+ CachedAsset((ContentType::JavaScript, js_bundle()))
}
#[get("/assets/bundle.js.map")]
-pub fn r_assets_js_map() -> (ContentType, String) {
- (ContentType::JSON, js_bundle_map())
+pub fn r_assets_js_map() -> CachedAsset<(ContentType, String)> {
+ CachedAsset((ContentType::JSON, js_bundle_map()))
}