Files
packager/rust/src/view/mod.rs

117 lines
3.9 KiB
Rust
Raw Normal View History

2023-08-29 21:33:59 +02:00
use maud::{html, Markup, PreEscaped, DOCTYPE};
2023-05-08 00:05:45 +02:00
pub mod home;
pub mod inventory;
2023-05-18 00:11:52 +02:00
pub mod trip;
2023-05-17 17:47:26 +02:00
2023-08-29 21:33:59 +02:00
pub struct Root;
2023-05-08 00:05:45 +02:00
2023-08-29 21:34:00 +02:00
use crate::TopLevelPage;
2023-05-08 00:05:45 +02:00
impl Root {
2023-08-29 21:34:00 +02:00
pub fn build(body: &Markup, active_page: Option<&TopLevelPage>) -> Markup {
let menu_item = |item: TopLevelPage, active_page: Option<&TopLevelPage>| {
let active = active_page.map(|page| *page == item).unwrap_or(false);
html!(
a
href=(item.path())
hx-boost="true"
#{"header-link-" (item.id())}
."px-5"
."flex"
."h-full"
."text-lg"
."hover:bg-gray-300"
// invisible top border to fix alignment
."border-t-gray-200"[active]
."hover:border-t-gray-300"[active]
."border-b-gray-500"[active]
."border-y-4"[active]
."font-bold"[active]
{ span ."m-auto" ."font-semibold" { (item.name()) }}
)
};
2023-08-29 21:33:59 +02:00
html!(
2023-05-08 22:31:01 +02:00
(DOCTYPE)
html {
head {
title { "Packager" }
2023-08-29 21:33:59 +02:00
script src="https://unpkg.com/htmx.org@1.9.2" {}
2023-08-29 21:33:59 +02:00
script src="https://unpkg.com/alpinejs@3.12.1" defer {}
2023-05-08 22:31:01 +02:00
script src="https://cdn.tailwindcss.com" {}
script src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.js" defer {}
2023-08-29 21:34:00 +02:00
link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mdi/font@6.9.96/css/materialdesignicons.min.css" {}
link rel="shortcut icon" type="image/svg+xml" href="/favicon.svg" {}
2023-08-29 21:33:59 +02:00
script { (PreEscaped(include_str!(concat!(env!("CARGO_MANIFEST_DIR"),"/js/app.js")))) }
2023-08-29 21:34:00 +02:00
meta name="htmx-config" content=r#"{"useTemplateFragments":true}"# {}
2023-05-08 22:31:01 +02:00
}
2023-08-29 21:33:59 +02:00
body
{
2023-05-08 22:31:01 +02:00
header
2023-08-29 21:34:00 +02:00
#header
2023-08-29 21:34:00 +02:00
."h-16"
2023-05-08 22:31:01 +02:00
."bg-gray-200"
."flex"
."flex-row"
."flex-nowrap"
."justify-between"
2023-08-29 21:34:00 +02:00
."items-stretch"
2023-05-08 22:31:01 +02:00
{
2023-08-29 21:34:00 +02:00
a
#home
hx-boost="true"
href="/"
2023-08-29 21:33:59 +02:00
."flex"
."flex-row"
."items-center"
."gap-3"
2023-08-29 21:34:00 +02:00
."px-5"
."hover:bg-gray-300"
2023-08-29 21:33:59 +02:00
{
2023-08-29 21:34:00 +02:00
img ."h-12" src="/assets/luggage.svg" {}
2023-08-29 21:34:00 +02:00
span
."text-xl"
."font-semibold"
{ "Packager" }
2023-05-08 22:31:01 +02:00
}
2023-08-29 21:33:59 +02:00
nav
."grow"
."flex"
."flex-row"
."justify-center"
."gap-x-10"
2023-08-29 21:34:00 +02:00
."items-stretch"
2023-08-29 21:33:59 +02:00
{
2023-08-29 21:34:00 +02:00
(menu_item(TopLevelPage::Inventory, active_page))
(menu_item(TopLevelPage::Trips, active_page))
2023-05-08 22:31:01 +02:00
}
}
2023-08-29 21:33:59 +02:00
(body)
2023-05-08 22:31:01 +02:00
}
}
2023-08-29 21:33:59 +02:00
)
2023-05-08 00:05:45 +02:00
}
2023-08-29 21:33:59 +02:00
}
pub struct ErrorPage;
2023-05-08 00:05:45 +02:00
2023-08-29 21:33:59 +02:00
impl ErrorPage {
pub fn build(message: &str) -> Markup {
2023-08-29 21:33:59 +02:00
html!(
(DOCTYPE)
html {
head {
title { "Packager" }
}
body {
2023-08-29 21:33:59 +02:00
h1 { "Error" }
p { (message) }
2023-08-29 21:33:59 +02:00
}
}
2023-08-29 21:33:59 +02:00
)
2023-05-08 00:05:45 +02:00
}
}