146 lines
5.3 KiB
Rust
146 lines
5.3 KiB
Rust
use crate::Language;
|
|
use axum_messages::Messages;
|
|
use maud::{html, Markup, DOCTYPE};
|
|
|
|
// TODO: set dynamic meta lang attribute
|
|
|
|
pub(crate) struct Page {
|
|
lang: Language,
|
|
found_camera: Option<String>,
|
|
new_name: bool,
|
|
err: Option<(String, String, String)>,
|
|
}
|
|
|
|
impl Page {
|
|
pub fn new(lang: Language) -> Self {
|
|
Self {
|
|
lang,
|
|
found_camera: None,
|
|
new_name: false,
|
|
err: None,
|
|
}
|
|
}
|
|
|
|
pub fn messages(&mut self, messages: Messages) {
|
|
for message in messages {
|
|
let text = &message.to_string()[..];
|
|
match (message.level, text) {
|
|
(_, "set-name-succ") => {
|
|
self.new_name = true;
|
|
}
|
|
(_, msg) if msg.starts_with("found-cam|") => {
|
|
let (_, name) = msg.split_once('|').expect("we just checked |");
|
|
self.found_camera = Some(name.into());
|
|
}
|
|
(_, msg) if msg.starts_with("err|") => {
|
|
let mut parts = msg.splitn(4, '|');
|
|
let _ = parts.next().expect("just checked |");
|
|
if let (Some(title), Some(body), Some(footer)) =
|
|
(parts.next(), parts.next(), parts.next())
|
|
{
|
|
self.err = Some((title.into(), body.into(), footer.into()));
|
|
}
|
|
}
|
|
(_, _) => {}
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn content(self, content: Markup) -> Markup {
|
|
rust_i18n::set_locale(self.lang.to_locale());
|
|
|
|
html! {
|
|
(DOCTYPE)
|
|
html lang=(self.lang) {
|
|
head {
|
|
meta charset="utf-8";
|
|
meta name="viewport" content="width=device-width, initial-scale=1.0";
|
|
link rel="stylesheet" href="/static/pico.min.css";
|
|
link rel="stylesheet" href="/static/style.css";
|
|
title { "Digital Shadows" }
|
|
}
|
|
body {
|
|
header.container {
|
|
nav {
|
|
ul {
|
|
li {
|
|
a href="/" {
|
|
strong { "Digital Shadows" }
|
|
}
|
|
}
|
|
}
|
|
ul {
|
|
li {
|
|
a href="/" {
|
|
span role="img" aria-label="home" { (t!("icon_home")) }
|
|
}
|
|
}
|
|
li {
|
|
a href="/game" {
|
|
span role="img" aria-label="camera" { (t!("icon_camera")) }
|
|
}
|
|
}
|
|
li {
|
|
span id="theme_switcher" {}
|
|
}
|
|
|
|
li {
|
|
button id="lang-toggle" lang=(self.lang.next_language()) {
|
|
(self.lang.next_language())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
main.container {
|
|
@if let Some(found_camera) = &self.found_camera {
|
|
div.flex {
|
|
article class="succ msg" {
|
|
header { (t!("found_camera_title", name = found_camera)) }
|
|
(t!("found_camera_body"))
|
|
" "
|
|
a href="#ranking" { "See your ranking" }
|
|
footer { (found_camera) }
|
|
}
|
|
}
|
|
}
|
|
@if self.new_name {
|
|
div.flex {
|
|
article class="name msg" {
|
|
header { "New name!" }
|
|
"Does it feel much different?"
|
|
}
|
|
}
|
|
}
|
|
@if let Some(err) = &self.err {
|
|
div.flex {
|
|
article class="error msg" {
|
|
header { (err.0) }
|
|
(err.1)
|
|
footer { (err.2) }
|
|
}
|
|
}
|
|
}
|
|
|
|
section { (content) }
|
|
}
|
|
|
|
footer.container {
|
|
small {
|
|
"Footer "
|
|
mark { "to be completed" }
|
|
a href="#" { "with links" }
|
|
" • "
|
|
a target="_blank" href="https://www.digidow.eu/impressum/" {
|
|
"Impressum"
|
|
}
|
|
}
|
|
}
|
|
script src="/static/theme.js" {}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|