Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(web): keep card motion and drop queued moves after a failed save

Tin42888e414bb6
diff --git a/apps/web/src/components/kanban-board/column/column-dropzone.tsx b/apps/web/src/components/kanban-board/column/column-dropzone.tsx
index e747f4879..fbeb24b54 100644
--- a/apps/web/src/components/kanban-board/column/column-dropzone.tsx
+++ b/apps/web/src/components/kanban-board/column/column-dropzone.tsx
@@ -3,36 +3,63 @@ import {
type SortingStrategy,
verticalListSortingStrategy,
} from "@dnd-kit/sortable";
+import { AnimatePresence, motion, useReducedMotion } from "framer-motion";
import type { ProjectWithTasks } from "@/types/project";
import TaskCard from "../task-card";
const keepOrder: SortingStrategy = () => null;
+const CARD_ENTER = { type: "spring", duration: 0.3, bounce: 0 } as const;
+const CARD_EXIT = { duration: 0.15, ease: [0.23, 1, 0.32, 1] } as const;
+
type ColumnDropzoneProps = {
column: ProjectWithTasks["columns"][number];
+ activeTaskId: string | null;
disableDragDrop?: boolean;
disableSorting?: boolean;
};
export function ColumnDropzone({
column,
+ activeTaskId,
disableDragDrop = false,
disableSorting = false,
}: ColumnDropzoneProps) {
+ const reduceMotion = useReducedMotion();
+ const hidden = reduceMotion
+ ? { opacity: 0 }
+ : { opacity: 0, transform: "scale(0.98)" };
+ const shown = reduceMotion
+ ? { opacity: 1 }
+ : { opacity: 1, transform: "scale(1)" };
+
return (
<SortableContext
items={column.tasks}
strategy={disableSorting ? keepOrder : verticalListSortingStrategy}
>
<div className="flex flex-col gap-1.5">
- {column.tasks.map((task) => (
- <TaskCard
- key={task.id}
- task={task}
- disableDragDrop={disableDragDrop}
- isFinalColumn={column.isFinal}
- />
- ))}
+ <AnimatePresence initial={false} mode="popLayout">
+ {column.tasks.map((task) => (
+ <motion.div
+ key={task.id}
+ initial={task.id === activeTaskId ? false : hidden}
+ animate={shown}
+ exit={
+ task.id === activeTaskId
+ ? undefined
+ : { ...hidden, transition: CARD_EXIT }
+ }
+ transition={CARD_ENTER}
+ >
+ <TaskCard
+ task={task}
+ disableDragDrop={disableDragDrop}
+ isFinalColumn={column.isFinal}
+ />
+ </motion.div>
+ ))}
+ </AnimatePresence>
</div>
</SortableContext>
);
diff --git a/apps/web/src/components/kanban-board/column/index.tsx b/apps/web/src/components/kanban-board/column/index.tsx
index 670d76fd5..052280f84 100644
--- a/apps/web/src/components/kanban-board/column/index.tsx
+++ b/apps/web/src/components/kanban-board/column/index.tsx
@@ -9,6 +9,7 @@ import { ColumnSortHint } from "./column-sort-hint";
type ColumnProps = {
column: ProjectWithTasks["columns"][number];
+ activeTaskId: string | null;
sortHint?: string;
disableDragDrop?: boolean;
disableSorting?: boolean;
@@ -61,6 +62,7 @@ export const columnVariants = cva(
function Column({
column,
+ activeTaskId,
sortHint,
disableDragDrop = false,
disableSorting = false,
@@ -89,6 +91,7 @@ function Column({
<div className="min-h-0 flex-1 overflow-y-auto overflow-x-hidden px-1.5 pt-1.5 pb-1.5 [-webkit-overflow-scrolling:touch]">
<ColumnDropzone
column={column}
+ activeTaskId={activeTaskId}
disableDragDrop={disableDragDrop}
disableSorting={disableSorting}
/>
diff --git a/apps/web/src/components/kanban-board/index.tsx b/apps/web/src/components/kanban-board/index.tsx
index 92b7c4f38..f43e5407f 100644
--- a/apps/web/src/components/kanban-board/index.tsx
+++ b/apps/web/src/components/kanban-board/index.tsx
@@ -190,7 +190,7 @@ function KanbanBoard({
const commitMove = (
activeId: string,
overId: string,
- onSettled: () => void,
+ onSettled: (failed?: boolean) => void,
insertAfterTarget?: boolean,
) => {
if (!project?.columns || disableDragDrop) {
@@ -227,7 +227,7 @@ function KanbanBoard({
expectedTasks: moved.expectedTasks,
previousBoard: canonical,
},
- { onSettled },
+ { onSettled: (_result, error) => onSettled(Boolean(error)) },
);
};
@@ -264,7 +264,7 @@ function KanbanBoard({
layout: "board",
selection: useBulkSelectionStore,
getGroups: () =>
- (project?.columns ?? []).map((column) => ({
+ queuedProject.columns.map((column) => ({
id: column.id,
taskIds: column.tasks.map((task) => task.id),
})),
@@ -357,6 +357,7 @@ function KanbanBoard({
>
<Column
column={column}
+ activeTaskId={activeId?.toString() ?? null}
sortHint={
column.id === sortHintColumnId
? t("tasks:kanban.automaticallySortedHint", {
diff --git a/apps/web/src/components/kanban-board/use-board-move-queue.test.ts b/apps/web/src/components/kanban-board/use-board-move-queue.test.ts
index 7a5e038ab..35dbcaf01 100644
--- a/apps/web/src/components/kanban-board/use-board-move-queue.test.ts
+++ b/apps/web/src/components/kanban-board/use-board-move-queue.test.ts
@@ -54,6 +54,26 @@ it("waits for each save even before the mutation's pending state renders", () =>
expect(onMove).toHaveBeenCalledTimes(2);
});
+it("drops queued moves when a save fails", () => {
+ const onMove = vi.fn();
+ const { result } = renderHook(() =>
+ useBoardMoveQueue({
+ projectId: "p",
+ waiting: false,
+ disabled: false,
+ onMove,
+ onCancel: vi.fn(),
+ }),
+ );
+ act(() => {
+ result.current.queueMove({ activeId: "a", overId: "b" });
+ result.current.queueMove({ activeId: "c", overId: "a" });
+ });
+ act(() => onMove.mock.calls[0][1](true));
+ expect(onMove).toHaveBeenCalledOnce();
+ expect(result.current.pendingMoves).toEqual([]);
+});
+
it("applies an idle drop synchronously before the drag preview is cleared", () => {
const onMove = vi.fn();
const { result } = renderHook(() =>
diff --git a/apps/web/src/components/kanban-board/use-board-move-queue.ts b/apps/web/src/components/kanban-board/use-board-move-queue.ts
index 0e0002918..6f4b9a2d8 100644
--- a/apps/web/src/components/kanban-board/use-board-move-queue.ts
+++ b/apps/web/src/components/kanban-board/use-board-move-queue.ts
@@ -16,7 +16,7 @@ export function useBoardMoveQueue({
projectId: string;
waiting: boolean;
disabled: boolean;
- onMove: (move: BoardMove, onSettled: () => void) => void;
+ onMove: (move: BoardMove, onSettled: (failed?: boolean) => void) => void;
onCancel: () => void;
}) {
const [queue, setQueue] = useState<Array<BoardMove & { projectId: string }>>(
@@ -28,9 +28,10 @@ export function useBoardMoveQueue({
(move: BoardMove) => {
// Mutation pending state can lag the next queued drop.
processing.current = true;
- onMove(move, () => {
+ onMove(move, (failed) => {
processing.current = false;
- setQueue((queue) => [...queue]);
+ // Queued drops were aimed at the board this failed move would have made.
+ setQueue((queue) => (failed ? [] : [...queue]));
});
},
[onMove],