diff --git a/crates/izlek-web/src/board.rs b/crates/izlek-web/src/board.rs index ccc592c..0d2267c 100644 --- a/crates/izlek-web/src/board.rs +++ b/crates/izlek-web/src/board.rs @@ -1,10 +1,10 @@ //! The board, from the Main artboard. //! -//! The whole column list is one shard: the server renders every column and -//! card, and a drop re-runs it in place. There is no client board state to -//! keep in sync with the server — a drag's only client-side memory is the -//! browser's own drag session (`dataTransfer`), read back by the column that -//! catches the drop. +//! The server renders every column and card; a drop posts `/api/move_card` +//! over `fetch` and swaps the redirected page in via `layout.rs`'s +//! `soft_nav_script`. There is no client board state to keep in sync with +//! the server — a drag's only client-side memory is the browser's own drag +//! session (`dataTransfer`), read back by the column that catches the drop. use izlek_core::board::{DeadlineState, Moved, Person, TaskCard}; use izlek_core::store::{NewTask, User}; @@ -14,7 +14,6 @@ use topcoat::context::Cx; use topcoat::router::content::Form; use topcoat::router::request::headers; use topcoat::router::{HeaderName, StatusCode, header, query_params, route}; -use topcoat::runtime::{Event, procedure, shard}; use topcoat::view::view; use crate::i18n::{Key, Lang, t}; @@ -170,7 +169,8 @@ struct MoveCardForm { to_column_id: String, } -/// The same move the drop procedure performs, reachable without script. +/// The one move path: the modal's status form, a card menu's "Move" rows +/// and the drop handler in `card_menu_script` all post here. #[route(POST "/api/move_card")] async fn move_card(cx: &Cx, Form(input): Form) -> Redirect { match move_card_shared(cx, &input.task_id, &input.from_column_id, &input.to_column_id).await? { @@ -179,22 +179,6 @@ async fn move_card(cx: &Cx, Form(input): Form) -> Redirect { } } -/// What a drop calls: performs the move and hands back a refusal code, if -/// any, for the drop handler to leave alone. Callable with any arguments — -/// the checks above are what actually guard it. -#[procedure] -async fn move_card_procedure( - cx: &Cx, - task_id: String, - from_column_id: String, - to_column_id: String, -) -> Result> { - match move_card_shared(cx, &task_id, &from_column_id, &to_column_id).await? { - Some(refusal) => Ok(Err(refusal.code().to_string())), - None => Ok(Ok(true)), - } -} - /// `deadline`, `created` or `title` — the "Sort" control in the filter bar. /// Anything else (a hand-edited or stale query string) falls back to /// `deadline` silently. @@ -220,11 +204,8 @@ fn sort_column_cards(cards: &mut [TaskCard], sort: &str) { } } -/// The whole column list. `version` carries no meaning of its own — bumping -/// it is what tells the browser to ask for this again after a drop lands. -#[shard] -async fn board_columns(cx: &Cx, version: f64, sort: String) -> Result { - let _ = version; +/// The whole column list. +async fn board_columns(cx: &Cx, sort: String) -> Result { let user = match require_user(cx).await { Ok(user) => user, Err(refusal) => { @@ -297,11 +278,9 @@ async fn render_column( } } -// The `@dragstart`/`@contextmenu` handlers below never read `e` as ordinary -// Rust — the `raw!` macro resolves `${e}` through its own name table, keyed -// on the closure param's identifier text, not through the generated closure -// body. -#[allow(unused_variables)] +// Drag and the context menu are delegated document listeners in +// `card_menu_script`, reading the card's `data-task-id`/`data-from-column` +// — per-element handlers would die when a soft submit swaps the board in. async fn render_card( cx: &Cx, card: TaskCard, @@ -337,27 +316,13 @@ async fn render_card( let menu_id = format!("card-menu-{}", card.id); let move_targets: Vec<(String, String)> = all_columns.iter().filter(|(id, _)| id != column_id).cloned().collect(); - // `raw!` interpolation only takes a bare identifier, and it moves what it - // takes — one clone per site that also needs the value afterward. - let drag_task_id = task_id.clone(); - let drag_from_column = from_column.clone(); - let open_menu_id = menu_id.clone(); - view! { cx => { ${e}.inner.dataTransfer.setData('izlek-task', ${drag_task_id}); ${e}.inner.dataTransfer.setData('izlek-from', ${drag_from_column}); })()", - () - )) - @contextmenu=$(|e: Event| { - e.prevent_default(); - raw!( - "(() => { window.__izlekOpenCardMenu(${e}.inner, ${open_menu_id}); })()", - () - ) - }) + data-task-id=(task_id.clone()) + data-from-column=(from_column.clone()) + data-menu-id=(menu_id.clone()) >
(card.task_key.clone()) @@ -439,7 +404,32 @@ async fn card_menu_script(cx: &Cx) -> Result { if (datepick) { datepick.checked = false; e.stopImmediatePropagation(); return; } \ var menu = document.querySelector('.card-menu-open'); \ if (menu) { closeCardMenus(); e.stopImmediatePropagation(); return; } \ - }, true)"; + }, true); \ + document.addEventListener('contextmenu', function (e) { \ + var card = e.target.closest ? e.target.closest('.card[data-menu-id]') : null; \ + if (!card) { return; } \ + e.preventDefault(); \ + window.__izlekOpenCardMenu(e, card.dataset.menuId); \ + }); \ + document.addEventListener('dragstart', function (e) { \ + var card = e.target.closest ? e.target.closest('.card[data-task-id]') : null; \ + if (!card) { return; } \ + e.dataTransfer.setData('izlek-task', card.dataset.taskId); \ + e.dataTransfer.setData('izlek-from', card.dataset.fromColumn); \ + }); \ + document.addEventListener('dragover', function (e) { \ + if (e.target.closest && e.target.closest('.board-columns')) { e.preventDefault(); } \ + }); \ + document.addEventListener('drop', function (e) { \ + var column = e.target.closest ? e.target.closest('.column-cards') : null; \ + if (!column) { return; } \ + e.preventDefault(); \ + var task = e.dataTransfer.getData('izlek-task'); \ + var from = e.dataTransfer.getData('izlek-from'); \ + if (task && window.__izlekPost) { \ + window.__izlekPost('/api/move_card', { task_id: task, from_column_id: from, to_column_id: column.id }); \ + } \ + })"; view! { cx => } } @@ -532,9 +522,7 @@ pub async fn board_page(cx: &Cx, user: &User) -> Result { }
(t(lang, Key::Sort)) - for key in SORT_KEYS { } @@ -553,28 +541,8 @@ pub async fn board_page(cx: &Cx, user: &User) -> Result {

(refusal.message_in(lang))

}
- signal version = 0.0; -
{ var col = ${e}.inner.target.closest('.column-cards'); return col ? col.id : ''; })())", - "".to_owned() - ); - let task_id = raw!("cx.hydrate(${e}.inner.dataTransfer.getData('izlek-task'))", "".to_owned()); - let from = raw!("cx.hydrate(${e}.inner.dataTransfer.getData('izlek-from'))", "".to_owned()); - if !task_id.is_empty() { - let _result = move_card_procedure(task_id, from, to).await; - version.set(version.get() + 1.0); - } - }) - > - board_columns(version: $(version.get()), sort: $(sort)) +
+ (board_columns(cx, sort.clone()).await?)
if let Some(task_id) = &open_task { diff --git a/crates/izlek-web/src/detail.rs b/crates/izlek-web/src/detail.rs index 16022f7..16101c4 100644 --- a/crates/izlek-web/src/detail.rs +++ b/crates/izlek-web/src/detail.rs @@ -26,7 +26,6 @@ use topcoat::context::Cx; use topcoat::router::content::{Form, Json}; use topcoat::router::request::headers; use topcoat::router::{HeaderName, StatusCode, header, route}; -use topcoat::runtime::Event; use topcoat::view::{class, view}; use crate::i18n::{Key, Lang, t}; @@ -535,20 +534,17 @@ async fn delete_file(cx: &Cx, Form(input): Form) -> Redirect { // Wasm-escapes from the old version, each simplified to a plain form post // rather than ported to a runtime signal (noted at each site below): // -// - StatusControl's and the file input's `on:change` auto-submit are back as -// a one-line `@change=$(|e: Event| raw!("${e}.inner.target.form.requestSubmit()", ()))` -// — a literal `@change="this.form.requestSubmit()"` runs immediately at -// attribute-scan time rather than on the event (topcoat's `data-topcoat-on:` -// handlers always call through the compiled-closure/`raw!` path; a bare JS -// string is evaluated once with no event or `this` bound) — and the -// "Move"/"Attach" buttons stay for a browser without script. -// - The modal scrim's click-to-close is back the same way: the scrim's own -// `@click` is a closure calling `raw!("window.location.href='/'", ())`, -// its inner `.modal` stops propagation with -// `@click=$(|e: Event| e.stop_propagation())`. The window `Escape` -// listener lives only in `board.rs`'s `card_menu_script` — this modal is -// always rendered alongside it. The X glyph and the footer "Close" button -// (plain links/buttons, no script) still work on their own. +// - StatusControl's and the file input's `on:change` auto-submit are the +// `data-autosubmit` attribute (and the file input's own class), read by +// `layout.rs`'s `soft_nav_script` through one delegated `change` +// listener — a per-element handler would die when a soft submit swaps +// the page in — and the "Move"/"Attach" buttons stay for a browser +// without script. +// - The modal scrim's click-to-close is `soft_nav_script`'s delegated +// click listener (a click whose target is the scrim itself closes; a +// click inside `.modal` never has the scrim as target, so no +// stop-propagation is needed). The X glyph and the footer "Close" link +// route through the same soft close. // - DeadlineControl's hand-built calendar grid (`js_sys::Date` for "today", // month navigation, per-day buttons) is replaced with a native // `` inside the same CSS-only edit-toggle popover — @@ -681,33 +677,32 @@ async fn avatar(cx: &Cx, person: &Person, extra: &str) -> Result { /// `Escape` for everything the task modal renders, topmost first: viewer → /// delete confirm (`confirm=delete` in URL) → open edit popovers → modal /// itself; datepick and card menu stay `board.rs`'s — this capture listener -/// registers first (inline in modal markup) and stops the key, and -/// `__izlekLeaving` is one navigation per document, `pageshow` releases it. -/// Focused native media controls swallow `Escape` before the page ever -/// sees the key, so focus landing on the viewer's audio/video is moved -/// straight back to the panel. Every branch that navigates must -/// `preventDefault()` first: a real Escape's browser default is -/// stop-loading, which cancels the navigation the handler just started -/// (and would leave `__izlekLeaving` latched true, deadening every -/// later press). Synthetic keys carry no default, so only a live -/// keyboard ever showed it. +/// registers first (inline in modal markup) and stops the key. Closing +/// never navigates: `layout.rs`'s `__izlekCloseViewer`/`__izlekCloseModal` +/// drop the overlay's DOM and rewrite the URL, the board underneath is +/// already rendered. Focused native media controls swallow `Escape` before +/// the page ever sees the key, so focus landing on the viewer's +/// audio/video is moved straight back to the panel. Every closing branch +/// still calls `preventDefault()`: a real Escape's browser default is +/// stop-loading (it once cancelled the navigation these branches used to +/// start; synthetic keys carry no default, so only a live keyboard ever +/// showed it). async fn escape_closes(cx: &Cx) -> Result { use topcoat::view::Unescaped; const JS: &str = "\ document.addEventListener('keydown', function (e) { \ if (e.key !== 'Escape') { return; } \ if (document.querySelector('.datepick-pop .edit-toggle:checked')) { return; } \ - var viewer = document.querySelector('.viewer-scrim'); \ - if (viewer) { \ + if (document.querySelector('.viewer-scrim')) { \ e.preventDefault(); \ - if (!window.__izlekLeaving) { window.__izlekLeaving = true; window.location.href = viewer.querySelector('.viewer-close').getAttribute('href'); } \ + window.__izlekCloseViewer(); \ e.stopImmediatePropagation(); \ return; \ } \ var confirm = document.querySelector('details.confirm-details[open]'); \ if (confirm && window.location.search.indexOf('confirm=delete') !== -1) { \ e.preventDefault(); \ - if (!window.__izlekLeaving) { window.__izlekLeaving = true; window.location.href = '/'; } \ + window.__izlekCloseModal(); \ e.stopImmediatePropagation(); \ return; \ } \ @@ -724,18 +719,17 @@ async fn escape_closes(cx: &Cx) -> Result { } \ if (document.querySelector('.modal-scrim')) { \ e.preventDefault(); \ - if (!window.__izlekLeaving) { window.__izlekLeaving = true; window.location.href = '/'; } \ + window.__izlekCloseModal(); \ e.stopImmediatePropagation(); \ } \ }, true); \ - document.addEventListener('pageshow', function () { window.__izlekLeaving = false; }); \ document.addEventListener('focusin', function (e) { \ var media = e.target; \ if (media.tagName !== 'AUDIO' && media.tagName !== 'VIDEO') { return; } \ var panel = media.closest('.viewer'); \ if (panel) { panel.focus(); } \ }, true); \ - document.addEventListener('click', function (e) { var confirm = document.querySelector('details.confirm-details[open]'); if (!confirm) { return; } var panel = confirm.querySelector('.confirm'); if (panel && !panel.contains(e.target) && !e.target.closest('summary')) { if (window.location.search.indexOf('confirm=delete') !== -1 && !window.__izlekLeaving) { window.__izlekLeaving = true; window.location.href = '/'; } else { confirm.removeAttribute('open'); } } }, true); \ + document.addEventListener('click', function (e) { var confirm = document.querySelector('details.confirm-details[open]'); if (!confirm) { return; } var panel = confirm.querySelector('.confirm'); if (panel && !panel.contains(e.target) && !e.target.closest('summary')) { if (window.location.search.indexOf('confirm=delete') !== -1) { window.__izlekCloseModal(); } else { confirm.removeAttribute('open'); } } }, true); \ document.addEventListener('click', function (e) { \ document.querySelectorAll('.edit-toggle:checked').forEach(function (toggle) { \ if (toggle.closest('.datepick-pop')) { return; } \ @@ -1152,10 +1146,6 @@ async fn comment_row(cx: &Cx, comment: &Comment, zone: UtcOffset) -> Result { /// dependencies, files, comments, activity and delete, exactly as the /// artboard draws them. Wiring `?task=` on the board page is a later /// integration slice — this only renders the fragment. -// Two `@change` handlers below never read `e` as ordinary Rust — the -// `raw!` macro resolves `${e}` through its own name table, keyed on the -// closure param's identifier text, not through the generated closure body. -#[allow(unused_variables)] pub async fn task_modal(cx: &Cx, task_id: &str, confirm_delete: bool) -> Result { let snapshot = match load_snapshot(cx, task_id).await? { Ok(snapshot) => snapshot, @@ -1167,8 +1157,8 @@ pub async fn task_modal(cx: &Cx, task_id: &str, confirm_delete: bool) -> Result let lang = require_user(cx).await.map(|user| Lang::from_code(&user.language)).unwrap_or(Lang::En); return view! { cx => -