From 4f9d1740c4b4a40ac2bc8a97bb2f51fc6b53a1cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 26 Aug 2026 10:25:47 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(board):=20drag=20a=20card=20ac?= =?UTF-8?q?ross,=20or=20say=20where=20it=20goes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The move is one server call that carries the column the card was believed to be in, so the store can refuse a drop decided against a board that has already changed underneath it. A refusal is shown, not swallowed. Two ways in, both real. The modal's STATUS control is a form and works with no script at all — it draws its own submit button only when an effect has proved the page is hydrated, and submits on change when it has. Drag and drop is the enhancement on top: a card is draggable once hydration runs, the column it is over shows the drop outline, and the drop posts the same call. A drop back into the card's own column posts nothing. --- crates/dizey-web/src/auth.rs | 6 ++ crates/dizey-web/src/board.rs | 107 +++++++++++++++++++++- crates/dizey-web/src/detail.rs | 105 ++++++++++++++++++++-- crates/dizey-web/tests/http.rs | 157 +++++++++++++++++++++++++++++++++ style/main.scss | 54 ++++++++++++ 5 files changed, 423 insertions(+), 6 deletions(-) diff --git a/crates/dizey-web/src/auth.rs b/crates/dizey-web/src/auth.rs index 2758dee..951be38 100644 --- a/crates/dizey-web/src/auth.rs +++ b/crates/dizey-web/src/auth.rs @@ -32,6 +32,9 @@ pub enum Refusal { BadDeadline, /// The link asked for would put a task behind itself. Cycle, + /// The card was already moved out of the column this request thought it + /// was in, by somebody else, while this person was deciding. + MovedAlready, /// No such task — or none this account may see. Deliberately one answer for /// both. NotFound, @@ -57,6 +60,9 @@ impl Refusal { Refusal::EmptyComment => "Write something first.".to_string(), Refusal::BadDeadline => "That is not a date.".to_string(), Refusal::Cycle => "That link would put this task behind itself.".to_string(), + Refusal::MovedAlready => { + "Somebody moved this card first. This is where it is now.".to_string() + } Refusal::NotFound => "No such task.".to_string(), Refusal::Unavailable => "Something went wrong. Try again.".to_string(), } diff --git a/crates/dizey-web/src/board.rs b/crates/dizey-web/src/board.rs index 4eb4702..bdbefd6 100644 --- a/crates/dizey-web/src/board.rs +++ b/crates/dizey-web/src/board.rs @@ -99,6 +99,59 @@ pub async fn create_task( Ok(None) } +/// Moves a card into a column and, with it, records the crossing. +/// +/// `from_column_id` is the column the browser had the card in when the drag +/// started or the status control was opened. It travels with the request so +/// the store can refuse a drop that was decided against a board somebody else +/// has already changed, rather than silently overwriting their move. +#[server] +pub async fn move_card( + task_id: String, + from_column_id: String, + to_column_id: String, +) -> Result, ServerFnError> { + use crate::detail::guard::writer_and_task; + use crate::server::accounts; + use dizey_core::board::Moved; + use time::OffsetDateTime; + + let (user, facts) = match writer_and_task(&task_id).await { + Ok(pair) => pair, + Err(refusal) => return Ok(Some(refusal)), + }; + // The destination is checked against this task's own board before the + // store is asked, so a column id from another board is refused by the + // handler and not merely by a foreign key. + let store = accounts().store().clone(); + let fail = |e: dizey_core::store::StoreError| ServerFnError::new(e.to_string()); + let columns = store.columns(&facts.board_id).await.map_err(fail)?; + if !columns.iter().any(|column| column.id == to_column_id) { + return Ok(Some(Refusal::Forbidden)); + } + + match store + .move_task( + &task_id, + &from_column_id, + &to_column_id, + &user.id, + OffsetDateTime::now_utc(), + ) + .await + { + // A card dropped back where it came from is not news and is not an + // error: the board simply re-reads and looks the same. + Ok(Moved::Recorded(_)) | Ok(Moved::Unchanged) => Ok(None), + Ok(Moved::Stale) => Ok(Some(Refusal::MovedAlready)), + Err(dizey_core::store::StoreError::NotFound) => Ok(Some(Refusal::NotFound)), + Err(error) => { + eprintln!("store error: {error}"); + Ok(Some(Refusal::Unavailable)) + } + } +} + /// Which cards the filter row is showing. #[derive(Clone, Copy, Debug, PartialEq, Eq)] enum Filter { @@ -174,6 +227,18 @@ fn BoardScreen( let filter = RwSignal::new(Filter::All); // Which column has its composer open, if any. let composing = RwSignal::new(None::); + // The card currently in the air, and the column it was picked up from. + // The column it came from is the drag's claim about the board it started + // on, and it travels with the drop so a move decided against a stale board + // is refused rather than applied. + let dragging = RwSignal::new(None::<(String, String)>); + let moving = ServerAction::::new(); + let moved = moving.value(); + Effect::new(move |_| { + if matches!(moved.get(), Some(Ok(_))) { + on_change(); + } + }); let may_write = me.role.can_write_tasks(); let my_id = StoredValue::new(me.id.clone()); @@ -231,12 +296,43 @@ fn BoardScreen( } })} -
+
@@ -351,6 +447,9 @@ fn Card( card: TaskCard, today: Date, done_column: bool, + /// A viewer cannot move work, so a viewer's cards do not lift. + draggable: bool, + dragging: RwSignal>, on_open: impl Fn(String) + Copy + Send + Sync + 'static, ) -> impl IntoView { let blocks = card.blocks.len(); @@ -361,6 +460,7 @@ fn Card( let comments = card.comment_count; let assignees = card.assignees.clone(); let id = StoredValue::new(card.id.clone()); + let from_column = StoredValue::new(card.column_id.clone()); let open = move || on_open(id.get_value()); view! { @@ -371,6 +471,11 @@ fn Card( class:card-done=done_column role="button" tabindex="0" + draggable=draggable.then_some("true") + on:dragstart=move |_| { + dragging.set(Some((id.get_value(), from_column.get_value()))); + } + on:dragend=move |_| dragging.set(None) on:click=move |_| open() on:keydown=move |event| { if event.key() == "Enter" || event.key() == " " { diff --git a/crates/dizey-web/src/detail.rs b/crates/dizey-web/src/detail.rs index ece80d8..a44557d 100644 --- a/crates/dizey-web/src/detail.rs +++ b/crates/dizey-web/src/detail.rs @@ -8,6 +8,7 @@ use dizey_core::board::Person; use dizey_core::detail::{Comment, DeletionCost, DependencyEdge, TaskDetail}; +use leptos::either::Either; use leptos::prelude::*; use serde::{Deserialize, Serialize}; use time::Date; @@ -49,7 +50,7 @@ pub enum Direction { } #[cfg(feature = "ssr")] -mod guard { +pub(crate) mod guard { use crate::auth::Refusal; use dizey_core::detail::TaskFacts; use dizey_core::store::User; @@ -432,6 +433,85 @@ pub async fn delete_task(task_id: String) -> Result, ServerFnErr // -- the screen ------------------------------------------------------------- +/// The artboard's STATUS control: the column the card sits in, and the way to +/// put it in another one. +/// +/// It is a real `
` with a real ` + + + + + + + + } +} + /// Whatever a refused call said, rendered where the form that asked for it is. /// A refusal shown at the far end of a scrolling modal is a refusal nobody /// reads: the person clicked "Link a task" and the sentence has to land under @@ -545,6 +625,8 @@ fn DetailScreen( let description = detail.description.clone(); let description_field = detail.description.clone(); let status = detail.column.name.clone(); + let column_id = detail.column.id.clone(); + let columns = detail.columns.clone(); let deadline_input = detail.deadline_input(); let overdue = detail.is_overdue(today); let deadline_label = detail.deadline_label(today); @@ -555,12 +637,13 @@ fn DetailScreen( let comment = ServerAction::::new(); let link = ServerAction::::new(); let remove = ServerAction::::new(); + let move_to = ServerAction::::new(); // Deleting is two steps: ask what it would cost, then say it out loud and // let the person decide. The artboard's red button had no confirmation and // this action reaches other people's tasks. let ask = ServerAction::::new(); // Every action that lands re-reads the task and the board behind it. - for value in [save.value(), comment.value(), link.value()] { + for value in [save.value(), comment.value(), link.value(), move_to.value()] { Effect::new(move |_| { if matches!(value.get(), Some(Ok(None))) { on_change(); @@ -589,9 +672,21 @@ fn DetailScreen(
"STATUS" - // Read-only this slice: moving a card is the transition the - // mail rules watch, and it lands with the drag. - {status} + {if may_write { + Either::Left( + view! { + + }, + ) + } else { + Either::Right(view! { {status} }) + }} + {refused(move_to)}
diff --git a/crates/dizey-web/tests/http.rs b/crates/dizey-web/tests/http.rs index b9ff262..366ff3d 100644 --- a/crates/dizey-web/tests/http.rs +++ b/crates/dizey-web/tests/http.rs @@ -522,3 +522,160 @@ async fn a_member_may_delete_and_the_delete_is_soft() { .await; assert_eq!(answer.body, "{\"Err\":\"NotFound\"}"); } + +/// Every column id on the board, in order, read off the wire the way the +/// browser would. +async fn columns_of(app: &App, cookie: &str) -> Vec { + let answer = app + .post(path::(), Some(cookie), &[]) + .await; + assert_eq!(answer.status, StatusCode::OK, "{}", answer.body); + answer + .body + .split("{\"column\":{\"id\":\"") + .skip(1) + .filter_map(|rest| rest.split('"').next()) + .map(str::to_string) + .collect() +} + +#[tokio::test] +async fn a_viewer_who_posts_a_move_anyway_is_refused() { + let app = App::open().await; + let admin = admin(&app).await; + let viewer = invited(&app, &admin, "quiet@dizey.sh", "Quiet Reader", Role::Viewer).await; + let columns = columns_of(&app, &admin).await; + let task = a_task(&app, &admin, &columns[0], "Stays in Backlog").await; + + let answer = app + .post( + path::(), + Some(&viewer), + &[ + ("task_id", &task), + ("from_column_id", &columns[0]), + ("to_column_id", &columns[1]), + ], + ) + .await; + + assert_eq!(answer.status, StatusCode::OK, "{}", answer.body); + assert_eq!(answer.body, "\"Forbidden\""); + + // And nothing moved: the refusal is in the handler, not in the drawing. + let answer = app + .post( + path::(), + Some(&admin), + &[("task_id", &task)], + ) + .await; + assert!( + answer.body.contains(&columns[0]), + "the refused move happened anyway: {}", + answer.body + ); +} + +#[tokio::test] +async fn a_member_may_move_a_card() { + let app = App::open().await; + let admin = admin(&app).await; + let member = invited(&app, &admin, "mo@dizey.sh", "Mo Dubois", Role::Member).await; + let columns = columns_of(&app, &admin).await; + let task = a_task(&app, &admin, &columns[0], "Gets picked up").await; + + let answer = app + .post( + path::(), + Some(&member), + &[ + ("task_id", &task), + ("from_column_id", &columns[0]), + ("to_column_id", &columns[1]), + ], + ) + .await; + assert_eq!(answer.body, "null", "a member was refused: {}", answer.body); + + let answer = app + .post( + path::(), + Some(&admin), + &[("task_id", &task)], + ) + .await; + assert!(answer.body.contains("\"moved\""), "no move in the activity"); +} + +#[tokio::test] +async fn a_drop_decided_against_a_stale_board_is_refused() { + let app = App::open().await; + let admin = admin(&app).await; + let member = invited(&app, &admin, "mo@dizey.sh", "Mo Dubois", Role::Member).await; + let columns = columns_of(&app, &admin).await; + let task = a_task(&app, &admin, &columns[0], "Contested").await; + + // Two people picked the same card up out of Backlog. + let first = app + .post( + path::(), + Some(&admin), + &[ + ("task_id", &task), + ("from_column_id", &columns[0]), + ("to_column_id", &columns[1]), + ], + ) + .await; + assert_eq!(first.body, "null"); + + let second = app + .post( + path::(), + Some(&member), + &[ + ("task_id", &task), + ("from_column_id", &columns[0]), + ("to_column_id", &columns[2]), + ], + ) + .await; + assert_eq!(second.body, "\"MovedAlready\""); + + // The winner's move stands, and there is exactly one crossing. + let answer = app + .post( + path::(), + Some(&admin), + &[("task_id", &task)], + ) + .await; + assert_eq!( + answer.body.matches("\"moved\"").count(), + 1, + "the second drop wrote a crossing too: {}", + answer.body + ); +} + +#[tokio::test] +async fn a_card_cannot_be_moved_into_another_boards_column() { + let app = App::open().await; + let admin = admin(&app).await; + let columns = columns_of(&app, &admin).await; + let task = a_task(&app, &admin, &columns[0], "Stays put").await; + + let answer = app + .post( + path::(), + Some(&admin), + &[ + ("task_id", &task), + ("from_column_id", &columns[0]), + ("to_column_id", "00000000-0000-0000-0000-000000000000"), + ], + ) + .await; + assert_eq!(answer.body, "\"Forbidden\""); +} diff --git a/style/main.scss b/style/main.scss index 5b3a0f2..4038452 100644 --- a/style/main.scss +++ b/style/main.scss @@ -453,6 +453,14 @@ a { } } +/* Where a dragged card may land. Only columns it is not already in light up: + the card's own column is not a destination. */ +.column-drop { + outline: 1px dashed var(--border-strong); + outline-offset: 4px; + border-radius: 8px; +} + .card-done { background: #faf9f4; box-shadow: none; @@ -729,6 +737,52 @@ a { font-size: 13px; } +/* The artboard's STATUS control: a dot, the column name, and the chevron the + select draws for itself. It is a form, so it works without script; the + submit button beside it is drawn only when script is absent. */ +.status-form { + position: relative; + display: flex; + align-items: center; + gap: 8px; + min-height: 36px; + padding: 0 10px; + background: #faf9f6; + border: 1px solid var(--border-strong); + border-radius: var(--radius); +} + +.status-dot { + width: 7px; + height: 7px; + border-radius: 50%; + background: var(--accent); + flex-shrink: 0; +} + +.status-dot-done { background: #5c7b46; } + +.status-select { + flex-grow: 1; + border: none; + background: none; + font: inherit; + font-size: 13px; + color: inherit; + padding: 0; + cursor: pointer; + outline: none; +} + +.status-go { + border: 1px solid var(--border-strong); + border-radius: 4px; + background: var(--surface); + font-size: 11px; + padding: 2px 6px; + cursor: pointer; +} + .detail-overdue { border-color: #e8c9b8; color: #a04a24;