diff options
author | metamuffin <metamuffin@disroot.org> | 2023-06-13 23:26:31 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-06-13 23:26:31 +0200 |
commit | 3fb4e4117df9d668815e974dea6b2a29436c92af (patch) | |
tree | 6cc9e2c434c35b218582ca6c32e262524403eb48 /server/src/routes | |
parent | 876fe4bd1f64ecd131947d327e587c1aa295e32e (diff) | |
download | jellything-3fb4e4117df9d668815e974dea6b2a29436c92af.tar jellything-3fb4e4117df9d668815e974dea6b2a29436c92af.tar.bz2 jellything-3fb4e4117df9d668815e974dea6b2a29436c92af.tar.zst |
some cleanup
Diffstat (limited to 'server/src/routes')
-rw-r--r-- | server/src/routes/api/error.rs | 5 | ||||
-rw-r--r-- | server/src/routes/api/mod.rs | 5 | ||||
-rw-r--r-- | server/src/routes/ui/account/settings.rs | 7 | ||||
-rw-r--r-- | server/src/routes/ui/browser.rs | 5 | ||||
-rw-r--r-- | server/src/routes/ui/layout.rs | 6 | ||||
-rw-r--r-- | server/src/routes/ui/node.rs | 1 | ||||
-rw-r--r-- | server/src/routes/ui/player.rs | 2 | ||||
-rw-r--r-- | server/src/routes/ui/style/transition.js | 14 |
8 files changed, 36 insertions, 9 deletions
diff --git a/server/src/routes/api/error.rs b/server/src/routes/api/error.rs index c4ca989..a1d0588 100644 --- a/server/src/routes/api/error.rs +++ b/server/src/routes/api/error.rs @@ -1,3 +1,8 @@ +/* + 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) 2023 metamuffin <metamuffin.org> +*/ // TODO: Slightâ„¢ code duplication with `ui/error.rs` use crate::routes::ui::error::MyError; diff --git a/server/src/routes/api/mod.rs b/server/src/routes/api/mod.rs index 06c38cf..8f7190e 100644 --- a/server/src/routes/api/mod.rs +++ b/server/src/routes/api/mod.rs @@ -1,3 +1,8 @@ +/* + 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) 2023 metamuffin <metamuffin.org> +*/ pub mod error; use std::path::PathBuf; diff --git a/server/src/routes/ui/account/settings.rs b/server/src/routes/ui/account/settings.rs index d44aef4..e196b35 100644 --- a/server/src/routes/ui/account/settings.rs +++ b/server/src/routes/ui/account/settings.rs @@ -1,10 +1,13 @@ +/* + 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) 2023 metamuffin <metamuffin.org> +*/ use std::ops::Range; - use rocket::{ form::{self, validate::len, Contextual, Form}, get, post, FromForm, State, }; - use super::{format_form_error, hash_password}; use crate::{ database::Database, diff --git a/server/src/routes/ui/browser.rs b/server/src/routes/ui/browser.rs index 04d9b7c..d0c09b1 100644 --- a/server/src/routes/ui/browser.rs +++ b/server/src/routes/ui/browser.rs @@ -1,3 +1,8 @@ +/* + 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) 2023 metamuffin <metamuffin.org> +*/ use super::{account::session::Session, error::MyError, layout::DynLayoutPage, node::ItemCard}; use crate::library::{Library, Node}; use rocket::{get, State}; diff --git a/server/src/routes/ui/layout.rs b/server/src/routes/ui/layout.rs index ecccc7c..6900dc3 100644 --- a/server/src/routes/ui/layout.rs +++ b/server/src/routes/ui/layout.rs @@ -21,7 +21,7 @@ use rocket::{ use std::io::Cursor; markup::define! { - Layout<'a, Main: Render>(title: String, main: Main, class: Option<&'a str>, session: Option<Session>) { + Layout<'a, Main: Render>(title: String, main: Main, class: Option<&'a str>, session: Option<Session>, show_back: bool) { @markup::doctype() html { head { @@ -31,6 +31,7 @@ markup::define! { } body[class=class.unwrap_or("")] { nav { + @if *show_back { a[onclick="history.back()", href="#"] { "<- Back" } } h1 { a[href="/"] { @CONF.brand } } @if let Some(_) = session { a[href="/library"] { "My Library" } @@ -65,6 +66,7 @@ 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, } @@ -74,6 +76,7 @@ impl Default for LayoutPage<DynRender<'_>> { class: None, content: markup::new!(), title: String::new(), + show_back: false, } } } @@ -86,6 +89,7 @@ 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 f94e0ba..15ddc5e 100644 --- a/server/src/routes/ui/node.rs +++ b/server/src/routes/ui/node.rs @@ -32,6 +32,7 @@ pub async fn r_library_node( .context("retrieving library node")?; Ok(LayoutPage { title: node.title().to_string(), + show_back: node.get_item().is_ok(), content: markup::new! { @NodePage { node: &node } }, diff --git a/server/src/routes/ui/player.rs b/server/src/routes/ui/player.rs index 2fa2dc5..ba380d0 100644 --- a/server/src/routes/ui/player.rs +++ b/server/src/routes/ui/player.rs @@ -55,6 +55,8 @@ pub fn r_player( } @player_conf(item.clone(), !tracks.is_empty()) }, + show_back: true, + ..Default::default() }) } diff --git a/server/src/routes/ui/style/transition.js b/server/src/routes/ui/style/transition.js index 6a4477e..c125c42 100644 --- a/server/src/routes/ui/style/transition.js +++ b/server/src/routes/ui/style/transition.js @@ -10,8 +10,9 @@ globalThis.addEventListener("load", () => { patch_page() }) -globalThis.addEventListener("popstate", () => { - transition_to(window.location.href) +globalThis.addEventListener("popstate", (_e) => { + transition_to(window.location.href, true) + // transition_to(_e.state.href, true) }) function patch_page() { @@ -23,13 +24,13 @@ function patch_page() { }) } -async function transition_to(href) { - const trigger_load = prepare_load(href) +async function transition_to(href, back) { + const trigger_load = prepare_load(href, back) await fade(false) trigger_load() } -function prepare_load(href) { +function prepare_load(href, back) { const r_promise = fetch(href) return async () => { let rt = "" @@ -44,7 +45,8 @@ function prepare_load(href) { document.head.innerHTML = head document.body.outerHTML = body fade(true) - window.history.pushState({}, "", href) + // if (!back) window.history.pushState({href}, "", href) + if (!back) window.history.pushState({}, "", href) patch_page() } } |