diff --git a/.justfile b/.justfile index 7192e56..a2937eb 100644 --- a/.justfile +++ b/.justfile @@ -16,6 +16,9 @@ migrate: (docker-compose "run dbmate migrate") rollback: (docker-compose "run dbmate rollback") +build-frontend-watch: + watchexec --restart --watch frontend just build-frontend + build-frontend: #!/usr/bin/env bun import sassPlugin from "@alecodes/bun-plugin-sass"; diff --git a/Cargo.lock b/Cargo.lock index 29d38e4..4bdeaa6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -69,6 +69,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d6fd624c75e18b3b4c6b9caf42b1afe24437daaee904069137d8bab077be8b8" dependencies = [ "axum-core", + "axum-macros", "bytes", "form_urlencoded", "futures-util", @@ -116,6 +117,17 @@ dependencies = [ "tracing", ] +[[package]] +name = "axum-macros" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "604fde5e028fea851ce1d8570bbdc034bec850d157f7569d10f347d06808c05c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "axum-sqlx-tx" version = "0.10.0" @@ -226,7 +238,10 @@ checksum = "7e36cc9d416881d2e24f9a963be5fb1cd90966419ac844274161d10488b3e825" dependencies = [ "android-tzdata", "iana-time-zone", + "js-sys", "num-traits", + "serde", + "wasm-bindgen", "windows-targets 0.52.6", ] @@ -236,6 +251,7 @@ version = "0.1.0" dependencies = [ "axum", "axum-sqlx-tx", + "chrono", "minijinja", "minijinja-embed", "notify", diff --git a/Cargo.toml b/Cargo.toml index 7200bb1..6565179 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,8 +4,9 @@ version = "0.1.0" edition = "2021" [dependencies] -axum = "0.8.1" +axum = { version = "0.8.1", features = ["macros"] } axum-sqlx-tx = "0.10.0" +chrono = { version = "0.4.39", features = ["serde"] } minijinja = { version = "2.7.0", features = ["loader"] } minijinja-embed = "2.7.0" notify = "8.0.0" diff --git a/bunfig.toml b/bunfig.toml index f694d83..13998c5 100644 --- a/bunfig.toml +++ b/bunfig.toml @@ -3,5 +3,5 @@ plugins = ["bun-plugin-sass"] [install.scopes] -"@alecodes" = { token = "$NPM_REGISTRY_TOKEN", url = "https://git.alecodes.page/api/packages/alecodes/npm/" } -"@mini-strap" = { token = "$NPM_REGISTRY_TOKEN", url = "https://git.alecodes.page/api/packages/alecodes/npm/" } +"@alecodes" = { url = "https://git.alecodes.page/api/packages/alecodes/npm/" } +"@mini-strap" = { url = "https://git.alecodes.page/api/packages/alecodes/npm/" } diff --git a/frontend/templates/index.html b/frontend/templates/index.html index e69de29..824925a 100644 --- a/frontend/templates/index.html +++ b/frontend/templates/index.html @@ -0,0 +1,26 @@ +{% extends "base.html" %} + +{% block content %} + + + + + + + + + + + + {% for row in rows %} + + + + + + + + {% endfor %} + +
DatabaseVersionDatabase NameCurrent UserCurrent Timestamp
{{ row.database }}{{ row.version }}{{ row.current_database }}{{ row.current_user }}{{ row.current_timestamp }}
+{% endblock content %} diff --git a/src/lib.rs b/src/lib.rs index caec70c..8ff7559 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,12 +1,13 @@ mod error; pub mod router; +use axum::extract::FromRef; pub use error::{Error, Result, ResultTemplate}; use minijinja::{Environment, Template}; use serde::{Deserialize, Serialize}; -use std::sync::Arc; pub type Tx = axum_sqlx_tx::Tx; +pub type TxState = axum_sqlx_tx::State; #[derive(Serialize, Deserialize, Debug)] pub struct Link { @@ -15,13 +16,15 @@ pub struct Link { pub subpages: Vec, } +#[derive(Clone, FromRef)] pub struct AppState { tmpl_env: Environment<'static>, + tx: TxState, } impl AppState { - pub fn new(tmpl_env: Environment<'static>) -> Arc { - Arc::new(AppState { tmpl_env }) + pub fn new(tmpl_env: Environment<'static>, tx: TxState) -> Self { + AppState { tmpl_env, tx } } pub fn get_template(&self, name: &str) -> Result