From e95add145b6f5b7a0ebd95b59ec1dbe14d2a37df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 1 Sep 2026 23:21:17 +0300 Subject: [PATCH] Password refusal reaches soft-posted forms; deadline pick survives live refresh; mobile layout Soft-post fetches declare Accept: text/html so a refused change renders 'That did not work.' instead of failing silently; the five local back_to copies fold into one helper that strips stale refusal params. An unsaved deadline pick lived only in the DOM and the live-refresh morph copied the server's stale attribute over it: the input now owns its value the moment it is picked, syncAttrs skips owned attributes both ways, and a wire pass re-derives an open popover after each swap. Pages hold the no-document-scrollbar rule at phone widths: board columns become a sideways rail, the topbar pans internally down to 320px, modals go single-column, auth pages lock to the viewport. --- crates/izlek-web/src/auth.rs | 16 +-- crates/izlek-web/src/detail.rs | 44 +++++-- crates/izlek-web/src/layout.rs | 20 ++- crates/izlek-web/src/logs.rs | 15 +-- crates/izlek-web/src/rules.rs | 15 +-- crates/izlek-web/src/server.rs | 34 ++++++ crates/izlek-web/src/settings.rs | 5 + crates/izlek-web/src/tags.rs | 15 +-- style/_instrument.scss | 19 +++ style/_ledger.scss | 25 ++++ style/main.scss | 204 +++++++++++++++++++++++++++++++ 11 files changed, 343 insertions(+), 69 deletions(-) diff --git a/crates/izlek-web/src/auth.rs b/crates/izlek-web/src/auth.rs index 3295212..361b128 100644 --- a/crates/izlek-web/src/auth.rs +++ b/crates/izlek-web/src/auth.rs @@ -18,8 +18,8 @@ use topcoat::router::response::{IntoResponse, Response}; use topcoat::router::{HeaderName, StatusCode, header, route}; use crate::server::{ - Refusal, accounts, clear_session_cookie, client_label, mail, presented_session, require_admin, - require_user, set_session_cookie, + Refusal, accounts, back_to, clear_session_cookie, client_label, mail, presented_session, + require_admin, require_user, set_session_cookie, }; use crate::settings::encode_q; @@ -68,16 +68,6 @@ pub async fn invited_by_token(cx: &Cx, token: &str) -> Result> { })) } -/// The page a browser without script is sent back to on a 303: the page the -/// form was posted from, or home when there is no `Referer` to read. -fn back_to(cx: &Cx) -> String { - headers(cx) - .get(header::REFERER) - .and_then(|value| value.to_str().ok()) - .unwrap_or("/") - .to_string() -} - /// A 303 to [`back_to`], carrying `refusal` as the body for /// `carry_refusal_on_redirect` to read and copy onto the query. type Redirect = Result<(StatusCode, [(HeaderName, String); 1], Json>)>; @@ -85,7 +75,7 @@ type Redirect = Result<(StatusCode, [(HeaderName, String); 1], Json) -> Redirect { Ok(( StatusCode::SEE_OTHER, - [(header::LOCATION, back_to(cx))], + [(header::LOCATION, back_to(cx, "/"))], Json(refusal), )) } diff --git a/crates/izlek-web/src/detail.rs b/crates/izlek-web/src/detail.rs index 80e0a1d..8022353 100644 --- a/crates/izlek-web/src/detail.rs +++ b/crates/izlek-web/src/detail.rs @@ -26,12 +26,11 @@ use time::{Date, UtcOffset}; use topcoat::Result; use topcoat::context::Cx; use topcoat::router::content::{Form, Json}; -use topcoat::router::request::headers; use topcoat::router::{HeaderName, StatusCode, header, route}; use topcoat::view::{class, view}; use crate::i18n::{Key, Lang, t}; -use crate::server::{Refusal, accounts, mail, refusal_of, require_user, require_writer}; +use crate::server::{Refusal, accounts, back_to, mail, refusal_of, require_user, require_writer}; /// A task this board could be linked to: enough to name it in the picker and /// nothing more. @@ -203,18 +202,10 @@ async fn writer_and_task( /// uses for every one of its mutating calls. type Redirect = Result<(StatusCode, [(HeaderName, String); 1], Json>)>; -fn back_to(cx: &Cx) -> String { - headers(cx) - .get(header::REFERER) - .and_then(|value| value.to_str().ok()) - .unwrap_or("/") - .to_string() -} - fn redirect(cx: &Cx, refusal: Option) -> Redirect { Ok(( StatusCode::SEE_OTHER, - [(header::LOCATION, back_to(cx))], + [(header::LOCATION, back_to(cx, "/"))], Json(refusal), )) } @@ -1408,6 +1399,19 @@ pub(crate) async fn datepicker_grid( /// `Escape` closes the panel through the datepick resolver `board.rs`'s /// `card_menu_script` registers (priority 100 — see the table on /// `layout.rs`'s `escape_manager_script`). +/// +/// The popover is the surface the live refresh used to reset. A picked day +/// lives in the hidden input's `value` — and on a hidden input the property +/// *is* the attribute, so the morph's attribute sync read it as server-stale +/// bytes and wrote the old date back over the pick; the label it reverted, +/// the client-built grid it emptied, the month nav's `data-year`/`data-month` +/// it swept. So the pick declares itself the client's the moment it happens +/// (`__izlekOwn(input, [], ['value'])`, and the panel's month attrs when +/// `render` first sets them), and an `izlek:wire` repair pass re-derives the +/// rest from that value: the label of a popover holding an unsaved pick, and +/// the grid of one standing open. The pass runs on every wire — a repair, +/// not an install; closed popovers with no unsaved pick are left to the +/// server's own voice. pub(crate) async fn datepicker_script(cx: &Cx, lang: Lang) -> Result { use crate::i18n::datepicker_js_literals; use topcoat::view::Unescaped; @@ -1421,12 +1425,13 @@ pub(crate) async fn datepicker_script(cx: &Cx, lang: Lang) -> Result { function pad(n) {{ return String(n).padStart(2, '0'); }}\ function parseYmd(v) {{ if (!v) return null; var p = v.split('-'); if (p.length !== 3) return null; return {{ y: +p[0], m: +p[1], d: +p[2] }}; }}\ function todayYmd() {{ var t = new Date(); return {{ y: t.getFullYear(), m: t.getMonth() + 1, d: t.getDate() }}; }}\ + function speak(label, ymd) {{ label.textContent = ymd ? MONTHS[ymd.m - 1].slice(0, 3) + ' ' + pad(ymd.d) : (label.dataset.empty || ''); }}\ function render(panel) {{\ var input = panel.querySelector('.datepick-input');\ if (!input) {{ return; }}\ var sel = parseYmd(input.value);\ var t = todayYmd();\ - if (!panel.dataset.year) {{ var base = sel || t; panel.dataset.year = base.y; panel.dataset.month = base.m; }}\ + if (!panel.dataset.year) {{ var base = sel || t; panel.dataset.year = base.y; panel.dataset.month = base.m; window.__izlekOwn(panel, [], ['data-year', 'data-month']); }}\ var y = +panel.dataset.year, m = +panel.dataset.month;\ panel.querySelector('.datepick-title').textContent = MONTHS[m - 1] + ' ' + y;\ panel.querySelector('.datepick-weekdays').innerHTML = WEEKDAYS.map(function(w) {{ return '' + w + ''; }}).join('');\ @@ -1446,10 +1451,11 @@ pub(crate) async fn datepicker_script(cx: &Cx, lang: Lang) -> Result { var input = panel.querySelector('.datepick-input');\ if (!input) {{ return; }}\ input.value = ymd ? (ymd.y + '-' + pad(ymd.m) + '-' + pad(ymd.d)) : '';\ + window.__izlekOwn(input, [], ['value']);\ if (!ymd) {{ ['clock_hour', 'clock_minute'].forEach(function (name) {{ var box = panel.querySelector('[name=' + name + ']'); if (!box) {{ return; }} box.value = ''; var trig = box.__ddTrigger; if (trig) {{ trig.textContent = box.options[0].textContent; trig.setAttribute('aria-expanded', 'false'); }} var drop = box.__ddPanel; if (drop) {{ drop.classList.remove('dd-open'); drop.querySelectorAll('.dd-option-selected').forEach(function (r) {{ r.classList.remove('dd-option-selected'); r.setAttribute('aria-selected', 'false'); }}); }} }}); }} \ var pop = panel.closest('.datepick-pop');\ var label = pop.querySelector('.datepick-label');\ - if (label) {{ label.textContent = ymd ? (MONTHS[ymd.m - 1].slice(0, 3) + ' ' + pad(ymd.d)) : label.dataset.empty; }}\ + if (label) {{ speak(label, ymd); }}\ var toggle = pop.querySelector('.edit-toggle');\ if (toggle) {{ toggle.checked = false; }}\ if (input.hasAttribute('data-autosubmit') && input.form) {{ input.form.requestSubmit(); }}\ @@ -1460,6 +1466,18 @@ pub(crate) async fn datepicker_script(cx: &Cx, lang: Lang) -> Result { var panel = toggle.closest('.datepick-pop').querySelector('.datepick-panel');\ if (panel) {{ render(panel); }}\ }});\ + document.addEventListener('izlek:wire', function () {{\ + document.querySelectorAll('.datepick-pop').forEach(function (pop) {{\ + var panel = pop.querySelector('.datepick-panel');\ + if (!panel) {{ return; }}\ + var toggle = pop.querySelector('.edit-toggle');\ + if (toggle && toggle.checked) {{ render(panel); }}\ + var input = panel.querySelector('.datepick-input');\ + if (!input || !input.__izlekMine || input.__izlekMine.a.indexOf('value') === -1) {{ return; }}\ + var label = pop.querySelector('.datepick-label');\ + if (label) {{ speak(label, parseYmd(input.value)); }}\ + }});\ + }});\ document.addEventListener('click', function(e) {{\ var prev = e.target.closest('.datepick-prev');\ var next = e.target.closest('.datepick-next');\ diff --git a/crates/izlek-web/src/layout.rs b/crates/izlek-web/src/layout.rs index 8aa60dc..57435b7 100644 --- a/crates/izlek-web/src/layout.rs +++ b/crates/izlek-web/src/layout.rs @@ -118,7 +118,7 @@ pub async fn user_menu(cx: &Cx, me: &crate::detail::Me, lang: Lang) -> Result {
(me.display_name.clone())
@@ -201,6 +201,14 @@ pub async fn topbar_nav(cx: &Cx, active: NavPage, role: izlek_core::Role, lang: /// arrive with the swap because the redirect URL's query params rendered /// them server-side; `history.replaceState` keeps the address bar honest. /// +/// The replay declares `Accept: text/html`, because a replayed form post is a +/// form post asking for the page back: `carry_refusal_on_redirect` +/// (`server.rs`) copies a refusing 303's answer onto the `Location` only for a +/// caller that wants the page, and a bare `fetch` asks for `*/*` — under which +/// the refusal stayed in a body nobody reads and the click looked like nothing +/// happening. The password pane was where this was first felt: a wrong +/// current password and a right one landed on the same silent page. +/// /// Every fetch that ends in a swap carries the navigation counter it started /// under (`window.__izlekNav`), and its answer is thrown away if that counter /// has moved. Without it the newest paint is not the newest intent: the live @@ -338,6 +346,7 @@ pub async fn soft_nav_script(cx: &Cx) -> Result { for (i = to.attributes.length - 1; i >= 0; i--) { \ at = to.attributes[i]; \ if (at.name === 'class') { continue; } \ + if (own && own.a.indexOf(at.name) !== -1) { continue; } \ if (from.getAttribute(at.name) !== at.value) { from.setAttribute(at.name, at.value); } \ } \ for (i = from.attributes.length - 1; i >= 0; i--) { \ @@ -432,7 +441,7 @@ pub async fn soft_nav_script(cx: &Cx) -> Result { }; \ window.__izlekPost = function (action, fields) { \ var n = navStep(); \ - fetch(action, { method: 'POST', body: new URLSearchParams(fields) }).then( \ + fetch(action, { method: 'POST', headers: { accept: 'text/html' }, body: new URLSearchParams(fields) }).then( \ function (r) { return r.text().then(function (t) { if (stillCurrent(n)) { swap(t, r.url); } }); }, \ function () {} \ ); \ @@ -475,7 +484,7 @@ pub async fn soft_nav_script(cx: &Cx) -> Result { var data = e.submitter ? new FormData(form, e.submitter) : new FormData(form); \ var multipart = (form.getAttribute('enctype') || '').indexOf('multipart') !== -1; \ var n = navStep(); \ - fetch(form.getAttribute('action'), { method: 'POST', body: multipart ? data : new URLSearchParams(data) }).then( \ + fetch(form.getAttribute('action'), { method: 'POST', headers: { accept: 'text/html' }, body: multipart ? data : new URLSearchParams(data) }).then( \ function (r) { return r.text().then(function (t) { if (stillCurrent(n)) { swap(t, r.url); } }); }, \ function () { form.submit(); } \ ); \ @@ -624,7 +633,10 @@ pub async fn soft_nav_script(cx: &Cx) -> Result { /// defined here — before any script that could enhance anything runs. /// `syncAttrs` then merges `class` (the server's list plus whatever owned /// classes are still on the node) instead of overwriting it, and skips owned -/// attributes when it sweeps. Nothing in this file mentions a dropdown. +/// attributes both when it copies the server's over and when it sweeps the +/// ones the server no longer has — an owned attribute is the client's fact, +/// stale server bytes say nothing against it. Nothing in this file mentions +/// a dropdown. /// /// The other half of the contract is `izlek:wire`: an enhancement re-derives /// whatever it draws from server data rather than assuming it is still true. diff --git a/crates/izlek-web/src/logs.rs b/crates/izlek-web/src/logs.rs index 1b938f8..b10db64 100644 --- a/crates/izlek-web/src/logs.rs +++ b/crates/izlek-web/src/logs.rs @@ -15,13 +15,12 @@ use time::format_description::well_known::Rfc3339; use topcoat::Result; use topcoat::context::Cx; use topcoat::router::content::{Form, Json}; -use topcoat::router::request::headers; use topcoat::router::{HeaderName, StatusCode, header, page, route}; use topcoat::view::view; use crate::detail::{Me, datepicker_grid}; use crate::i18n::{Key, Lang, t}; -use crate::server::{Refusal, accounts, require_admin}; +use crate::server::{Refusal, accounts, back_to, require_admin}; use crate::settings::{decode_q, encode_q}; /// One send still owed or refused, as the queue panel reads it. @@ -748,16 +747,6 @@ async fn current_logs(cx: &Cx) -> Result String { - headers(cx) - .get(header::REFERER) - .and_then(|value| value.to_str().ok()) - .unwrap_or("/logs?section=queue") - .to_string() -} - /// A 303 to [`back_to`], carrying `refusal` as the body for /// `crate::server::carry_refusal_on_redirect` to read and copy onto the query. type Redirect = Result<(StatusCode, [(HeaderName, String); 1], Json>)>; @@ -765,7 +754,7 @@ type Redirect = Result<(StatusCode, [(HeaderName, String); 1], Json) -> Redirect { Ok(( StatusCode::SEE_OTHER, - [(header::LOCATION, back_to(cx))], + [(header::LOCATION, back_to(cx, "/logs?section=queue"))], Json(refusal), )) } diff --git a/crates/izlek-web/src/rules.rs b/crates/izlek-web/src/rules.rs index 007f31e..9c4e60a 100644 --- a/crates/izlek-web/src/rules.rs +++ b/crates/izlek-web/src/rules.rs @@ -20,7 +20,6 @@ use serde::{Deserialize, Serialize}; use topcoat::Result; use topcoat::context::Cx; use topcoat::router::content::{Form, Json}; -use topcoat::router::request::headers; use topcoat::router::{HeaderName, StatusCode, header, page, query_params, route}; use topcoat::view::view; @@ -28,7 +27,7 @@ use izlek_core::board::Column; use izlek_core::store::{Audience, Store, Trigger, User, Workspace}; use crate::i18n::{Key, Lang, t}; -use crate::server::{Refusal, accounts, refusal_of, require_admin}; +use crate::server::{Refusal, accounts, back_to, refusal_of, require_admin}; /// One rule as the screen reads it: a sentence, a switch and a stamp. /// @@ -384,16 +383,6 @@ async fn current_rules(cx: &Cx) -> Result String { - headers(cx) - .get(header::REFERER) - .and_then(|value| value.to_str().ok()) - .unwrap_or("/") - .to_string() -} - /// A 303 to [`back_to`], carrying `refusal` as the body for /// `crate::server::carry_refusal_on_redirect` to read and copy onto the query. type Redirect = Result<(StatusCode, [(HeaderName, String); 1], Json>)>; @@ -401,7 +390,7 @@ type Redirect = Result<(StatusCode, [(HeaderName, String); 1], Json) -> Redirect { Ok(( StatusCode::SEE_OTHER, - [(header::LOCATION, back_to(cx))], + [(header::LOCATION, back_to(cx, "/"))], Json(refusal), )) } diff --git a/crates/izlek-web/src/server.rs b/crates/izlek-web/src/server.rs index c195f94..b69dad3 100644 --- a/crates/izlek-web/src/server.rs +++ b/crates/izlek-web/src/server.rs @@ -655,6 +655,40 @@ pub fn refusal_of(cx: &Cx, call: &str) -> Option { Refusal::from_code(code?) } +/// The page a form was posted from: the `Referer`, with the answer any +/// earlier post left on its query dropped, or `nowhere` when no `Referer` +/// came with the request. +/// +/// The feedback pairs — `refusal=`, `on=`, `why=`, `saved=` — are how a page +/// renders what the last post did. Sending the browser back with them still +/// on the query re-renders that old answer under the new post's own: a change +/// that succeeded right after one that was refused announces the refusal +/// again, and reads as having failed. The answer this redirect carries — the +/// pairs it was built with, or the body [`carry_refusal_on_redirect`] copies +/// onto the query — is the one that shows; an earlier one never survives the +/// trip. +pub fn back_to(cx: &Cx, nowhere: &str) -> String { + let referer = headers(cx) + .get(header::REFERER) + .and_then(|value| value.to_str().ok()) + .unwrap_or(nowhere); + let (path, query) = referer.split_once('?').unwrap_or((referer, "")); + let pairs: Vec<&str> = query + .split('&') + .filter(|pair| { + !pair.is_empty() + && !["refusal", "on", "why", "saved"].iter().any(|key| { + pair.strip_prefix(*key) + .is_some_and(|rest| rest.starts_with('=')) + }) + }) + .collect(); + if pairs.is_empty() { + return path.to_string(); + } + format!("{path}?{}", pairs.join("&")) +} + /// Puts a refusal on the redirect a browser without script follows. /// /// A hydrated page reads the call's return value straight off the action. A diff --git a/crates/izlek-web/src/settings.rs b/crates/izlek-web/src/settings.rs index c4700ff..2d3c340 100644 --- a/crates/izlek-web/src/settings.rs +++ b/crates/izlek-web/src/settings.rs @@ -1583,6 +1583,10 @@ async fn settings_page(cx: &Cx) -> Result { (t(lang, Key::AdminOnly))
+ // The register keeps its named columns at every width; on a + // narrow screen this box pans it sideways, silently, instead + // of letting the columns crush the role select out. +
@@ -1667,6 +1671,7 @@ async fn settings_page(cx: &Cx) -> Result { }
+