Merge pull request 'Introduce JS for improved back button behaviour' (#121) from js_back_button into main

Reviewed-on: #121
This commit is contained in:
glyph 2022-06-28 08:14:42 +00:00
commit 123ebc06cc
4 changed files with 25 additions and 4 deletions

4
Cargo.lock generated
View File

@ -1079,7 +1079,7 @@ dependencies = [
[[package]]
name = "golgi"
version = "0.1.4"
source = "git+https://git.coopcloud.tech/golgi-ssb/golgi#ca4c1114ddf328b818144c5a1af0187b1357e9be"
source = "git+https://git.coopcloud.tech/golgi-ssb/golgi.git#ca4c1114ddf328b818144c5a1af0187b1357e9be"
dependencies = [
"async-std",
"async-stream 0.3.3",
@ -2331,7 +2331,7 @@ dependencies = [
[[package]]
name = "peach-web"
version = "0.6.17"
version = "0.6.18"
dependencies = [
"async-std",
"base64 0.13.0",

View File

@ -1,6 +1,6 @@
[package]
name = "peach-web"
version = "0.6.17"
version = "0.6.18"
authors = ["Andrew Reid <gnomad@cryptolab.net>", "Max Fowler <max@mfowler.info>"]
edition = "2018"
description = "peach-web is a web application which provides a web interface for monitoring and interacting with the PeachCloud device. This allows administration of the single-board computer (ie. Raspberry Pi) running PeachCloud, as well as the ssb-server and related plugins."

View File

@ -1,5 +1,25 @@
use maud::{html, PreEscaped, DOCTYPE};
/// JavaScript event listener for the back button on the top navigation bar of
/// the UI.
///
/// When the button is clicked, prevent the default behaviour and invoke
/// the history API to load the previous URL (page) in the history list.
fn js_back_button_script() -> PreEscaped<String> {
html! {
(PreEscaped("
<script>
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('backButton').onclick = function(e) {
e.preventDefault();
history.back();
}
});
</script>
"))
}
}
/// Base template builder.
///
/// Takes an HTML body as input and splices it into the base template.
@ -14,6 +34,7 @@ pub fn build_template(body: PreEscaped<String>, theme: String) -> PreEscaped<Str
meta name="viewport" content="width=devide-width, initial-scale=1.0";
link rel="stylesheet" href="/css/peachcloud.css";
link rel="stylesheet" href="/css/_variables.css";
(js_back_button_script())
title { "PeachCloud" }
}
body {

View File

@ -38,7 +38,7 @@ pub fn build_template(
html! {
(PreEscaped("<!-- Top navigation bar -->"))
nav class="nav-bar" {
a class="nav-item" href=[back] title="Back" {
a id="backButton" class="nav-item" href=[back] title="Back" {
img class="icon-medium nav-icon-left icon-active" src="/icons/back.svg" alt="Back";
}
h1 class="nav-title" { (title) }