From f20d1cc74be1522ffd36ddd31d78789ad13afdbc Mon Sep 17 00:00:00 2001 From: insects Date: Fri, 7 Feb 2025 15:22:24 +0100 Subject: [PATCH 1/3] add a little menu bar --- src/templates.rs | 5 +++++ static/style.css | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/templates.rs b/src/templates.rs index b681e1d..559059b 100644 --- a/src/templates.rs +++ b/src/templates.rs @@ -159,6 +159,11 @@ pub fn main_page( .header { div {} .side { + .menu { + span { "Beacon " (env!("CARGO_PKG_VERSION")) } + a href="/changelog" { "Changelog" } + a href="/logout" { "Log out" } + } details { summary { "Filters" } form { diff --git a/static/style.css b/static/style.css index cac2da3..1f51142 100644 --- a/static/style.css +++ b/static/style.css @@ -17,6 +17,12 @@ section { align-items: center; } +.side { + display: flex; + flex-direction: column; + align-items: end; +} + select { width: 100%; } @@ -145,3 +151,8 @@ h2.clock { summary:hover { cursor: pointer; } + +.menu { + display: flex; + gap: 5px; +} From 5f516f71f9ad22e53009ec2e04c9affde3e66f0b Mon Sep 17 00:00:00 2001 From: insects Date: Fri, 7 Feb 2025 15:35:44 +0100 Subject: [PATCH 2/3] add changelog and logout functionality --- src/changelog.rs | 25 +++++++++++++++++++++++++ src/main.rs | 12 ++++++++++++ static/scripts/logout.js | 9 +++++++++ static/style.css | 3 ++- 4 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/changelog.rs create mode 100644 static/scripts/logout.js diff --git a/src/changelog.rs b/src/changelog.rs new file mode 100644 index 0000000..9d98b68 --- /dev/null +++ b/src/changelog.rs @@ -0,0 +1,25 @@ +use maud::{html, Markup}; + +use crate::templates::layout; + +pub fn changelog_page() -> Markup { + layout(html! { + h1 { "Beacon Changelog" } + + section { + h2 { "1.1.0, 07.02.2025" } + ul { + li { "Fish now directly display their non-relative dates for their next or current window" } + li { "Additionally, fish that are up now display the starting time for the subsequent window" } + li { "The site now saves your account ID in your browser storage, and automatically redirects you on page visit" } + } + } + + section { + h2 { "1.0.0, 06.02.2025" } + ul { + li { "Initial release" } + } + } + }) +} diff --git a/src/main.rs b/src/main.rs index d8c6e46..f2c82f6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,9 +12,11 @@ use maud::{html, Markup}; use nanoid::nanoid; use serde::Deserialize; use sqlx::{postgres::PgPoolOptions, Pool, Postgres}; +use templates::layout; use tower_http::{services::ServeDir, trace::TraceLayer}; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; +pub mod changelog; pub mod clock; pub mod data; pub mod db; @@ -146,6 +148,16 @@ async fn main() { .route("/to", get(to_handler)) .route("/{id}", get(main_handler)) .route("/{acc_id}/catch/{fish_id}", post(insert_cf_handler)) + .route("/changelog", get(|| async { changelog::changelog_page() })) + .route( + "/logout", + get(|| async { + layout(html! { + h1 { "Logging you out, please wait to be redirected..." } + script src="/static/scripts/logout.js" type="text/javascript" {} + }) + }), + ) .layer(TraceLayer::new_for_http()) .nest_service("/static", ServeDir::new("static")) .with_state(Arc::new(AppState { diff --git a/static/scripts/logout.js b/static/scripts/logout.js new file mode 100644 index 0000000..93b6356 --- /dev/null +++ b/static/scripts/logout.js @@ -0,0 +1,9 @@ +// Removes the local storage entry, and redirects to the index page. +const ls = window.localStorage; +if (ls.getItem("beacon:account-id")) { + console.log("a"); + ls.removeItem("beacon:account-id"); + window.location.pathname = "/"; +} else { + window.location.pathname = "/"; +} diff --git a/static/style.css b/static/style.css index 1f51142..2f58d9e 100644 --- a/static/style.css +++ b/static/style.css @@ -3,7 +3,8 @@ body { margin: 40px; } -section { +section.up, +section.always-up { margin-bottom: 5px; display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; From 1fd7009e251a17e9d12edb1c1ef0a75e3c4d3241 Mon Sep 17 00:00:00 2001 From: insects Date: Fri, 7 Feb 2025 15:37:17 +0100 Subject: [PATCH 3/3] also save account id when logging in normally --- src/templates.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/templates.rs b/src/templates.rs index 559059b..146531b 100644 --- a/src/templates.rs +++ b/src/templates.rs @@ -156,6 +156,7 @@ pub fn main_page( }; let template = html! { + span style="display: none;" id="account-id" { (acc_id) } .header { div {} .side { @@ -207,6 +208,8 @@ pub fn main_page( div id="list" hx-get="" hx-trigger="every 10s" hx-swap="innerHTML" hx-target="this" hx-on="changeDates" { (list) } + + script src="/static/scripts/save.js" type="text/javascript" {} }; if only_list {