From 23b90b3dd79ec195f5ab0cc867189c5215ef6e36 Mon Sep 17 00:00:00 2001 From: Jakub Doka Date: Tue, 15 Oct 2024 12:46:36 +0200 Subject: [PATCH] adding tab highlight and some more details in readme --- depell/README.md | 6 +++++- depell/src/index.css | 6 ++++-- depell/src/index.js | 18 +++++++++++++++++- depell/src/main.rs | 32 ++++++++++++++++++++++++-------- 4 files changed, 50 insertions(+), 12 deletions(-) diff --git a/depell/README.md b/depell/README.md index b5576bf..6ba46ab 100644 --- a/depell/README.md +++ b/depell/README.md @@ -1,10 +1,14 @@ # Depell -Depell is a website that allows users to import/post/run hblang code and create huge dependency graphs +Depell is a website that allows users to import/post/run hblang code and create huge dependency graphs. ## Local Development +Prerequirements: +- rust nigthly toolchain: install rust from [here](https://www.rust-lang.org/tools/install) + ```bash +rustup default nightly cargo xtask watch-depell-debug # browser http://localhost:8080 ``` diff --git a/depell/src/index.css b/depell/src/index.css index 57ec65f..ae7f55c 100644 --- a/depell/src/index.css +++ b/depell/src/index.css @@ -10,6 +10,7 @@ body { --placeholder: #333333; } + body { --small-gap: 5px; --font: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; @@ -81,6 +82,7 @@ pre { margin: 0px; font-family: var(--monospace); tab-size: 4; + overflow-x: auto; } input { @@ -92,7 +94,7 @@ input { } input:is(:hover, :focus) { - background: white; + background: var(--primary); } button { @@ -103,7 +105,7 @@ button { } button:hover:not(:active) { - background: white; + background: var(--primary); } div#code-editor { diff --git a/depell/src/index.js b/depell/src/index.js index 79ce0e8..304d317 100644 --- a/depell/src/index.js +++ b/depell/src/index.js @@ -331,6 +331,13 @@ function cacheInputs(target) { } } +function updaetTab() { + for (const elem of document.querySelectorAll("button[hx-push-url]")) { + if (elem instanceof HTMLButtonElement) + elem.disabled = elem.getAttribute("hx-push-url") === window.location.pathname; + } +} + if (window.location.hostname === 'localhost') { let id; setInterval(async () => { let new_id = await fetch('/hot-reload').then(reps => reps.text()); @@ -361,8 +368,17 @@ if (window.location.hostname === 'localhost') { document.body.addEventListener('htmx:afterSwap', (ev) => { if (!(ev.target instanceof HTMLElement)) never(); wireUp(ev.target); + if (ev.target.tagName == "MAIN") updaetTab(); }); +//document.body.addEventListener('htmx:beforeSend', (ev) => { +// const target = ev.target; +// if (target instanceof HTMLButtonElement && target.hasAttribute("hx-push-url")) { +// +// document.getElementById("extra-style").textContent = `[hx-push-url="${target.getAttribute("hx-push-url")}"]{background: var(--primary)}` +// } +//}); + getFmtInstance().then(inst => { document.body.addEventListener('htmx:configRequest', (ev) => { const details = ev['detail']; @@ -411,6 +427,6 @@ getFmtInstance().then(inst => { Object.assign(window, { filterCodeDeps }); }); - +updaetTab(); wireUp(document.body); diff --git a/depell/src/main.rs b/depell/src/main.rs index dbc5bae..1c71391 100644 --- a/depell/src/main.rs +++ b/depell/src/main.rs @@ -3,7 +3,7 @@ use { argon2::{password_hash::SaltString, PasswordVerifier}, axum::{ body::Bytes, - extract::Path, + extract::{OriginalUri, Path}, http::{header::COOKIE, request::Parts}, response::{AppendHeaders, Html}, }, @@ -349,8 +349,16 @@ impl Profile { Profile { other: Some(name) }.render(&session) } - async fn get_other_page(session: Session, Path(name): Path) -> Html { - base(|b| Profile { other: Some(name) }.render_to_buf(&session, b), Some(&session)) + async fn get_other_page( + session: Session, + path: axum::extract::OriginalUri, + Path(name): Path, + ) -> Html { + base( + |b| Profile { other: Some(name) }.render_to_buf(&session, b), + path.path(), + Some(&session), + ) } } @@ -534,7 +542,7 @@ impl Signup { } } -fn base(body: impl FnOnce(&mut String), session: Option<&Session>) -> Html { +fn base(body: impl FnOnce(&mut String), path: &str, session: Option<&Session>) -> Html { let username = session.map(|s| &s.name); let nav_button = |f: &mut String, name: &str| { @@ -550,7 +558,12 @@ fn base(body: impl FnOnce(&mut String), session: Option<&Session>) -> Html" + + + //