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(backlog): prevent task remounts during list interactions (#1734)

Tin Severc65ab40daa4e
diff --git a/apps/web/src/components/backlog-list-view/backlog-section.tsx b/apps/web/src/components/backlog-list-view/backlog-section.tsx
new file mode 100644
index 000000000..253089d78
--- /dev/null
+++ b/apps/web/src/components/backlog-list-view/backlog-section.tsx
@@ -0,0 +1,127 @@
+import { useDroppable } from "@dnd-kit/core";
+import {
+ SortableContext,
+ verticalListSortingStrategy,
+} from "@dnd-kit/sortable";
+import { AnimatePresence, motion } from "framer-motion";
+import { ChevronRight, type Clock, Plus } from "lucide-react";
+import { memo } from "react";
+import { useTranslation } from "react-i18next";
+import { cn } from "@/lib/cn";
+import type Task from "@/types/task";
+import BacklogTaskRow from "./backlog-task-row";
+
+const BacklogSection = memo(function BacklogSection({
+ sectionId,
+ title,
+ icon: IconComponent,
+ tasks,
+ isExpanded,
+ showDropIndicator,
+ onToggle,
+ onAddTask,
+}: {
+ sectionId: string;
+ title: string;
+ icon: typeof Clock;
+ tasks: Task[];
+ isExpanded: boolean;
+ showDropIndicator: boolean;
+ onToggle: (sectionId: string) => void;
+ onAddTask?: () => void;
+}) {
+ const { t } = useTranslation();
+ const { setNodeRef } = useDroppable({
+ id: sectionId,
+ data: {
+ type: "column",
+ column: { id: sectionId, name: title },
+ },
+ });
+
+ return (
+ <div
+ className={cn(
+ "border-b border-border/50 transition-colors duration-150 overflow-auto",
+ showDropIndicator && "border-l-4 border-l-ring bg-accent/35",
+ )}
+ >
+ <div className="flex items-center justify-between py-2 px-4 bg-muted/60 border-b border-border/50">
+ <button
+ type="button"
+ onClick={() => onToggle(sectionId)}
+ aria-expanded={isExpanded}
+ className="flex items-center gap-2 text-sm font-medium text-foreground hover:text-foreground transition-colors"
+ >
+ <ChevronRight
+ className={cn(
+ "w-3 h-3 transition-transform",
+ isExpanded && "rotate-90",
+ )}
+ />
+ <div className="flex items-center gap-2 h-4">
+ <IconComponent className="w-4 h-4 flex-shrink-0 text-muted-foreground" />
+ <div className="flex items-center gap-1">
+ <span className="mt-1 mr-1">
+ {t(`tasks:backlog.sections.${sectionId}`, {
+ defaultValue: title,
+ })}
+ </span>
+ <span className="text-xs text-muted-foreground mt-0.5">
+ {tasks.length}
+ </span>
+ </div>
+ </div>
+ </button>
+
+ <div className="flex items-center gap-1">
+ {onAddTask && (
+ <button
+ type="button"
+ onClick={onAddTask}
+ className="p-1 hover:bg-accent rounded text-muted-foreground hover:text-foreground transition-colors"
+ title={t("tasks:backlog.addTask")}
+ >
+ <Plus className="w-3 h-3" />
+ </button>
+ )}
+ </div>
+ </div>
+
+ {isExpanded && (
+ <div
+ ref={setNodeRef}
+ className="bg-card transition-[translate,opacity] duration-150 ease-out starting:-translate-y-1 starting:opacity-0 motion-reduce:starting:translate-y-0"
+ >
+ <SortableContext items={tasks} strategy={verticalListSortingStrategy}>
+ <AnimatePresence initial={false} mode="popLayout">
+ {tasks.map((task) => (
+ <motion.div
+ key={task.id}
+ initial={{ opacity: 0 }}
+ animate={{ opacity: 1 }}
+ exit={{ opacity: 0 }}
+ transition={{ duration: 0.15, ease: [0.23, 1, 0.32, 1] }}
+ >
+ <BacklogTaskRow task={task} />
+ </motion.div>
+ ))}
+ </AnimatePresence>
+ </SortableContext>
+
+ {tasks.length === 0 && (
+ <div className="py-6 px-4 text-center text-xs text-muted-foreground">
+ {t("tasks:backlog.noTasksInSection", {
+ section: t(`tasks:backlog.sections.${sectionId}`, {
+ defaultValue: title,
+ }).toLowerCase(),
+ })}
+ </div>
+ )}
+ </div>
+ )}
+ </div>
+ );
+});
+
+export default BacklogSection;
diff --git a/apps/web/src/components/backlog-list-view/backlog-task-row.test.tsx b/apps/web/src/components/backlog-list-view/backlog-task-row.test.tsx
new file mode 100644
index 000000000..bba93629a
--- /dev/null
+++ b/apps/web/src/components/backlog-list-view/backlog-task-row.test.tsx
@@ -0,0 +1,206 @@
+import {
+ act,
+ cleanup,
+ fireEvent,
+ render,
+ screen,
+} from "@testing-library/react";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import useBacklogBulkSelectionStore from "@/store/backlog-bulk-selection";
+import useProjectStore from "@/store/project";
+import type { ProjectWithTasks } from "@/types/project";
+import type Task from "@/types/task";
+import BacklogTaskRow from "./backlog-task-row";
+
+const { useSortable } = vi.hoisted(() => ({
+ useSortable: vi.fn((_options: { id: string }) => ({
+ attributes: { role: "button" },
+ listeners: {},
+ setNodeRef: vi.fn(),
+ transform: null,
+ transition: null,
+ isDragging: false,
+ })),
+}));
+vi.mock("@dnd-kit/sortable", () => ({ useSortable }));
+vi.mock("@tanstack/react-router", () => ({ useNavigate: () => vi.fn() }));
+vi.mock("@/hooks/mutations/task/use-delete-task", () => ({
+ useDeleteTask: () => ({ mutateAsync: vi.fn() }),
+}));
+vi.mock("@/hooks/queries/workspace/use-active-workspace", () => ({
+ default: () => ({ data: { id: "workspace-1" } }),
+}));
+vi.mock(
+ "@/hooks/queries/workspace-users/use-get-active-workspace-users",
+ () => ({
+ useGetActiveWorkspaceUsers: () => ({ data: { members: [] } }),
+ }),
+);
+vi.mock(
+ "@/hooks/queries/custom-field/use-get-custom-field-values-by-project",
+ () => ({
+ default: () => ({ data: [] }),
+ }),
+);
+vi.mock(
+ "../kanban-board/task-card-context-menu/task-card-context-menu-content",
+ () => ({
+ default: () => null,
+ }),
+);
+vi.mock("@/store/user-preferences", () => ({
+ useUserPreferencesStore: () => ({ showLabels: true, showTaskNumbers: true }),
+}));
+vi.mock("react-i18next", () => ({
+ useTranslation: () => ({ t: (key: string) => key }),
+ initReactI18next: { type: "3rdParty", init: vi.fn() },
+}));
+
+const task: Task = {
+ id: "task-1",
+ title: "First task",
+ number: 1,
+ description: null,
+ status: "planned",
+ priority: null,
+ startDate: null,
+ dueDate: null,
+ position: 0,
+ createdAt: "2026-09-16T00:00:00.000Z",
+ userId: null,
+ assigneeId: null,
+ assigneeName: null,
+ projectId: "project-1",
+ labels: [],
+};
+const otherTask = { ...task, id: "task-2", title: "Second task" };
+
+const project: ProjectWithTasks = {
+ id: "project-1",
+ workspaceId: "workspace-1",
+ name: "Imported project",
+ slug: "IMP",
+ icon: null,
+ description: null,
+ isPublic: false,
+ columns: [],
+ plannedTasks: [task, otherTask],
+ archivedTasks: [],
+};
+
+beforeEach(() => {
+ useProjectStore.setState({ project });
+ useBacklogBulkSelectionStore.setState(
+ useBacklogBulkSelectionStore.getInitialState(),
+ );
+ vi.clearAllMocks();
+});
+afterEach(cleanup);
+
+describe("backlog row subscriptions", () => {
+ it("only renders the row whose selection changes, including deselection", () => {
+ render(
+ <>
+ <BacklogTaskRow task={task} />
+ <BacklogTaskRow task={otherTask} />
+ </>,
+ );
+ useSortable.mockClear();
+
+ fireEvent.click(screen.getByRole("button", { name: /First task/ }), {
+ ctrlKey: true,
+ });
+ expect(useSortable.mock.calls.map(([options]) => options.id)).toEqual([
+ "task-1",
+ ]);
+ expect(screen.getByRole("button", { name: /First task/ })).toHaveClass(
+ "bg-accent/45",
+ );
+
+ useSortable.mockClear();
+ act(() => useBacklogBulkSelectionStore.getState().clearSelection());
+ expect(useSortable.mock.calls.map(([options]) => options.id)).toEqual([
+ "task-1",
+ ]);
+ expect(screen.getByRole("button", { name: /First task/ })).not.toHaveClass(
+ "bg-accent/45",
+ );
+ });
+
+ it("updates focus highlights without rendering rows on available-task changes", () => {
+ render(
+ <>
+ <BacklogTaskRow task={task} />
+ <BacklogTaskRow task={otherTask} />
+ </>,
+ );
+ useSortable.mockClear();
+ act(() =>
+ useBacklogBulkSelectionStore
+ .getState()
+ .setAvailableTasks([task.id, otherTask.id]),
+ );
+ expect(useSortable).not.toHaveBeenCalled();
+
+ act(() => useBacklogBulkSelectionStore.getState().focusNext());
+ expect(useSortable.mock.calls.map(([options]) => options.id)).toEqual([
+ "task-1",
+ ]);
+ expect(
+ screen.getByRole("button", { name: /First task/ }).closest(".ring-2"),
+ ).not.toBeNull();
+
+ useSortable.mockClear();
+ act(() => useBacklogBulkSelectionStore.getState().focusNext());
+ expect(
+ useSortable.mock.calls.map(([options]) => options.id).sort(),
+ ).toEqual(["task-1", "task-2"]);
+ expect(
+ screen.getByRole("button", { name: /First task/ }).closest(".ring-2"),
+ ).toBeNull();
+ expect(
+ screen.getByRole("button", { name: /Second task/ }).closest(".ring-2"),
+ ).not.toBeNull();
+ });
+
+ it("ignores unrelated project updates but keeps task numbers in sync with the slug", () => {
+ render(
+ <>
+ <BacklogTaskRow task={task} />
+ <BacklogTaskRow task={otherTask} />
+ </>,
+ );
+ useSortable.mockClear();
+ act(() =>
+ useProjectStore
+ .getState()
+ .setProject({ ...project, description: "Updated description" }),
+ );
+ expect(useSortable).not.toHaveBeenCalled();
+ act(() =>
+ useProjectStore.getState().setProject({ ...project, slug: "NEW" }),
+ );
+ expect(
+ useSortable.mock.calls.map(([options]) => options.id).sort(),
+ ).toEqual(["task-1", "task-2"]);
+ expect(screen.getAllByText("NEW-1")).toHaveLength(2);
+ });
+
+ it("skips unchanged task props but renders refreshed task data", () => {
+ const { rerender } = render(<BacklogTaskRow task={task} />);
+ useSortable.mockClear();
+ rerender(<BacklogTaskRow task={task} />);
+ expect(useSortable).not.toHaveBeenCalled();
+ rerender(
+ <BacklogTaskRow
+ task={{
+ ...task,
+ title: "Updated title",
+ labels: [{ id: "label-1", name: "Bug", color: "red" }],
+ }}
+ />,
+ );
+ expect(screen.getByText("Updated title")).toBeVisible();
+ expect(screen.getByText("Bug")).toBeVisible();
+ });
+});
diff --git a/apps/web/src/components/backlog-list-view/backlog-task-row.tsx b/apps/web/src/components/backlog-list-view/backlog-task-row.tsx
index 21aa1c94a..cd555bc8e 100644
--- a/apps/web/src/components/backlog-list-view/backlog-task-row.tsx
+++ b/apps/web/src/components/backlog-list-view/backlog-task-row.tsx
@@ -8,7 +8,7 @@ import {
CalendarX,
SlidersHorizontal,
} from "lucide-react";
-import { type CSSProperties, useMemo, useState } from "react";
+import { type CSSProperties, memo, useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import {
AlertDialog,
@@ -51,7 +51,9 @@ type BacklogTaskRowProps = {
task: Task;
};
-export default function BacklogTaskRow({ task }: BacklogTaskRowProps) {
+const BacklogTaskRow = memo(function BacklogTaskRow({
+ task,
+}: BacklogTaskRowProps) {
const { t } = useTranslation();
const navigate = useNavigate();
const {
@@ -63,8 +65,10 @@ export default function BacklogTaskRow({ task }: BacklogTaskRowProps) {
isDragging,
} = useSortable({ id: task.id });
- const { project } = useProjectStore();
- const taskIsCompleted = isTaskCompleted(task.status, project?.columns);
+ const projectId = useProjectStore((state) => state.project?.id);
+ const projectSlug = useProjectStore((state) => state.project?.slug);
+ const projectColumns = useProjectStore((state) => state.project?.columns);
+ const taskIsCompleted = isTaskCompleted(task.status, projectColumns);
const { data: workspace } = useActiveWorkspace();
const {
showAssignees,
@@ -75,10 +79,15 @@ export default function BacklogTaskRow({ task }: BacklogTaskRowProps) {
} = useUserPreferencesStore();
const [isDeleteTaskModalOpen, setIsDeleteTaskModalOpen] = useState(false);
const { mutateAsync: deleteTask } = useDeleteTask();
- const { toggleSelection, isSelected, isFocused } =
- useBacklogBulkSelectionStore();
- const isTaskSelected = isSelected(task.id);
- const isTaskFocused = isFocused(task.id);
+ const toggleSelection = useBacklogBulkSelectionStore(
+ (state) => state.toggleSelection,
+ );
+ const isTaskSelected = useBacklogBulkSelectionStore((state) =>
+ state.selectedTaskIds.has(task.id),
+ );
+ const isTaskFocused = useBacklogBulkSelectionStore(
+ (state) => state.focusedTaskId === task.id,
+ );
const { data: workspaceUsers } = useGetActiveWorkspaceUsers(
workspace?.id ?? "",
@@ -113,7 +122,7 @@ export default function BacklogTaskRow({ task }: BacklogTaskRowProps) {
};
const handleClick = (e: React.MouseEvent) => {
- if (!project || !task) return;
+ if (!projectId || !task) return;
if (e.defaultPrevented) return;
if (e.metaKey || e.ctrlKey) {
@@ -187,7 +196,7 @@ export default function BacklogTaskRow({ task }: BacklogTaskRowProps) {
)}
{showTaskNumbers && (
<div className="text-xs font-mono text-muted-foreground flex-shrink-0">
- {project?.slug}-{task.number}
+ {projectSlug}-{task.number}
</div>
)}
@@ -294,11 +303,11 @@ export default function BacklogTaskRow({ task }: BacklogTaskRowProps) {
</div>
</ContextMenuTrigger>
- {project && workspace && (
+ {projectId && workspace && (
<TaskCardContextMenuContent
task={task}
taskCardContext={{
- projectId: project.id,
+ projectId,
worskpaceId: workspace.id,
}}
onDeleteClick={() => setIsDeleteTaskModalOpen(true)}
@@ -337,4 +346,6 @@ export default function BacklogTaskRow({ task }: BacklogTaskRowProps) {
</AlertDialog>
</div>
);
-}
+});
+
+export default BacklogTaskRow;
diff --git a/apps/web/src/components/backlog-list-view/index.test.tsx b/apps/web/src/components/backlog-list-view/index.test.tsx
new file mode 100644
index 000000000..5ce20e426
--- /dev/null
+++ b/apps/web/src/components/backlog-list-view/index.test.tsx
@@ -0,0 +1,189 @@
+import {
+ act,
+ cleanup,
+ fireEvent,
+ render,
+ screen,
+} from "@testing-library/react";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import { KeyboardShortcutsProvider } from "@/hooks/use-keyboard-shortcuts";
+import useBacklogBulkSelectionStore from "@/store/backlog-bulk-selection";
+import type { ProjectWithTasks } from "@/types/project";
+import type Task from "@/types/task";
+import BacklogListView from "./index";
+
+const { mountRow, unmountRow, renderRow, navigate } = vi.hoisted(() => ({
+ mountRow: vi.fn(),
+ unmountRow: vi.fn(),
+ renderRow: vi.fn(),
+ navigate: vi.fn(),
+}));
+
+vi.mock("./backlog-task-row", async () => {
+ const { useEffect } = await import("react");
+ return {
+ default: ({ task }: { task: Task }) => {
+ renderRow(task.id);
+ useEffect(() => {
+ mountRow(task.id);
+ return () => unmountRow(task.id);
+ }, [task.id]);
+ return <input aria-label={task.id} defaultValue={task.title} />;
+ },
+ };
+});
+
+vi.mock("@tanstack/react-router", () => ({ useNavigate: () => navigate }));
+vi.mock("@/hooks/mutations/task/use-update-task", () => ({
+ useUpdateTask: () => ({ mutate: vi.fn() }),
+}));
+vi.mock("../shared/modals/create-task-modal", () => ({
+ default: ({ open, status }: { open: boolean; status: string }) =>
+ open ? <div role="dialog">{status}</div> : null,
+}));
+vi.mock("../bulk-selection/backlog-bulk-toolbar", () => ({
+ default: () => null,
+}));
+vi.mock("react-i18next", () => ({
+ useTranslation: () => ({ t: (key: string) => key }),
+ initReactI18next: { type: "3rdParty", init: vi.fn() },
+}));
+
+function makeTasks(status: string, count: number): Task[] {
+ return Array.from({ length: count }, (_, index) => ({
+ id: `${status}-${index}`,
+ title: `${status} task ${index}`,
+ status,
+ number: index,
+ description: null,
+ priority: null,
+ startDate: null,
+ dueDate: null,
+ position: index,
+ createdAt: "2026-09-16T00:00:00.000Z",
+ userId: null,
+ assigneeId: null,
+ assigneeName: null,
+ projectId: "project-1",
+ }));
+}
+
+const project: ProjectWithTasks = {
+ id: "project-1",
+ workspaceId: "workspace-1",
+ name: "Imported project",
+ slug: "IMP",
+ icon: null,
+ description: null,
+ isPublic: false,
+ columns: [],
+ // Exact lifecycle counts catch remounts without a large DOM slowing CI.
+ plannedTasks: makeTasks("planned", 2),
+ archivedTasks: makeTasks("archived", 3),
+};
+
+const totalTaskCount =
+ project.plannedTasks.length + project.archivedTasks.length;
+
+beforeEach(() => {
+ useBacklogBulkSelectionStore.setState(
+ useBacklogBulkSelectionStore.getInitialState(),
+ );
+ vi.clearAllMocks();
+});
+afterEach(cleanup);
+
+describe("backlog row lifecycle", () => {
+ it("mounts each row once and preserves the other section when collapsing and expanding", () => {
+ render(<BacklogListView project={project} />, {
+ wrapper: KeyboardShortcutsProvider,
+ });
+ expect(mountRow).toHaveBeenCalledTimes(totalTaskCount);
+ expect(unmountRow).not.toHaveBeenCalled();
+
+ const archivedRow = screen.getByLabelText("archived-0");
+ fireEvent.change(archivedRow, { target: { value: "Local row state" } });
+ mountRow.mockClear();
+ const plannedToggle = screen.getByRole("button", {
+ name: /tasks:backlog.sections.planned/,
+ });
+ fireEvent.click(plannedToggle);
+
+ expect(plannedToggle).toHaveAttribute("aria-expanded", "false");
+ expect(mountRow).not.toHaveBeenCalled();
+ expect(unmountRow).toHaveBeenCalledTimes(project.plannedTasks.length);
+ expect(screen.getByLabelText("archived-0")).toBe(archivedRow);
+ expect(archivedRow).toHaveValue("Local row state");
+ expect(useBacklogBulkSelectionStore.getState().availableTaskIds).toEqual(
+ project.archivedTasks.map((task) => task.id),
+ );
+
+ fireEvent.click(plannedToggle);
+ expect(plannedToggle).toHaveAttribute("aria-expanded", "true");
+ expect(mountRow).toHaveBeenCalledTimes(project.plannedTasks.length);
+ expect(unmountRow).toHaveBeenCalledTimes(project.plannedTasks.length);
+ expect(archivedRow).toHaveValue("Local row state");
+ expect(
+ useBacklogBulkSelectionStore.getState().availableTaskIds,
+ ).toHaveLength(totalTaskCount);
+ });
+
+ it("does not render the list again on selection or keyboard focus changes", () => {
+ render(<BacklogListView project={project} />, {
+ wrapper: KeyboardShortcutsProvider,
+ });
+ renderRow.mockClear();
+ mountRow.mockClear();
+
+ act(() =>
+ useBacklogBulkSelectionStore.getState().toggleSelection("planned-0"),
+ );
+ fireEvent.keyDown(document.body, { key: "j" });
+ expect(navigate).toHaveBeenLastCalledWith({
+ to: ".",
+ search: { taskId: "planned-0" },
+ });
+ fireEvent.keyDown(document.body, { key: "j" });
+ expect(navigate).toHaveBeenLastCalledWith({
+ to: ".",
+ search: { taskId: "planned-1" },
+ });
+ fireEvent.keyDown(document.body, { key: "Enter" });
+ expect(navigate).toHaveBeenLastCalledWith({
+ to: "/dashboard/workspace/$workspaceId/project/$projectId/task/$taskId",
+ params: {
+ workspaceId: "workspace-1",
+ projectId: "project-1",
+ taskId: "planned-1",
+ },
+ });
+ fireEvent.keyDown(document.body, { key: "k" });
+ expect(navigate).toHaveBeenLastCalledWith({
+ to: ".",
+ search: { taskId: "planned-0" },
+ });
+ expect(renderRow).not.toHaveBeenCalled();
+ expect(mountRow).not.toHaveBeenCalled();
+ expect(unmountRow).not.toHaveBeenCalled();
+ });
+
+ it("preserves rows when opening task creation or receiving updated task data", () => {
+ const { rerender } = render(<BacklogListView project={project} />, {
+ wrapper: KeyboardShortcutsProvider,
+ });
+ const archivedRow = screen.getByLabelText("archived-0");
+ mountRow.mockClear();
+ fireEvent.click(
+ screen.getByRole("button", { name: "tasks:backlog.addTask" }),
+ );
+ expect(screen.getByRole("dialog")).toHaveTextContent("planned");
+ rerender(
+ <BacklogListView
+ project={{ ...project, archivedTasks: [...project.archivedTasks] }}
+ />,
+ );
+ expect(screen.getByLabelText("archived-0")).toBe(archivedRow);
+ expect(mountRow).not.toHaveBeenCalled();
+ expect(unmountRow).not.toHaveBeenCalled();
+ });
+});
diff --git a/apps/web/src/components/backlog-list-view/index.tsx b/apps/web/src/components/backlog-list-view/index.tsx
index 754969af2..003d3ef44 100644
--- a/apps/web/src/components/backlog-list-view/index.tsx
+++ b/apps/web/src/components/backlog-list-view/index.tsx
@@ -9,20 +9,14 @@ import {
MouseSensor,
TouchSensor,
type UniqueIdentifier,
- useDroppable,
useSensor,
useSensors,
} from "@dnd-kit/core";
import { snapCenterToCursor } from "@dnd-kit/modifiers";
-import {
- SortableContext,
- verticalListSortingStrategy,
-} from "@dnd-kit/sortable";
import { useNavigate } from "@tanstack/react-router";
-import { AnimatePresence, motion } from "framer-motion";
import { produce } from "immer";
-import { Archive, ChevronRight, Clock, Flag, Plus } from "lucide-react";
-import { useEffect, useState } from "react";
+import { Archive, Clock, Flag } from "lucide-react";
+import { useCallback, useEffect, useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import { priorityColorsTaskCard } from "@/constants/priority-colors";
import { useUpdateTask } from "@/hooks/mutations/task/use-update-task";
@@ -31,10 +25,9 @@ import { cn } from "@/lib/cn";
import useBacklogBulkSelectionStore from "@/store/backlog-bulk-selection";
import useProjectStore from "@/store/project";
import type { ProjectWithTasks } from "@/types/project";
-import type Task from "@/types/task";
import BacklogBulkToolbar from "../bulk-selection/backlog-bulk-toolbar";
import CreateTaskModal from "../shared/modals/create-task-modal";
-import BacklogTaskRow from "./backlog-task-row";
+import BacklogSection from "./backlog-section";
type BacklogListViewProps = {
project?: ProjectWithTasks;
@@ -47,14 +40,15 @@ function BacklogListView({
}: BacklogListViewProps) {
const { t } = useTranslation();
const { mutate: updateTask } = useUpdateTask();
- const { setProject } = useProjectStore();
- const {
- setAvailableTasks,
- focusNext,
- focusPrevious,
- focusedTaskId,
- clearFocus,
- } = useBacklogBulkSelectionStore();
+ const setProject = useProjectStore((state) => state.setProject);
+ const setAvailableTasks = useBacklogBulkSelectionStore(
+ (state) => state.setAvailableTasks,
+ );
+ const focusNext = useBacklogBulkSelectionStore((state) => state.focusNext);
+ const focusPrevious = useBacklogBulkSelectionStore(
+ (state) => state.focusPrevious,
+ );
+ const clearFocus = useBacklogBulkSelectionStore((state) => state.clearFocus);
const navigate = useNavigate();
const [activeId, setActiveId] = useState<UniqueIdentifier | null>(null);
const [overColumnId, setOverColumnId] = useState<string | null>(null);
@@ -88,36 +82,41 @@ function BacklogListView({
clearFocus();
}, [clearFocus]);
- useRegisterShortcuts({
- shortcuts: {
- j: () => {
- focusNext();
- const state = useBacklogBulkSelectionStore.getState();
- if (state.focusedTaskId) {
- navigate({ to: ".", search: { taskId: state.focusedTaskId } });
- }
+ const keyboardShortcuts = useMemo(
+ () => ({
+ shortcuts: {
+ j: () => {
+ focusNext();
+ const state = useBacklogBulkSelectionStore.getState();
+ if (state.focusedTaskId) {
+ navigate({ to: ".", search: { taskId: state.focusedTaskId } });
+ }
+ },
+ k: () => {
+ focusPrevious();
+ const state = useBacklogBulkSelectionStore.getState();
+ if (state.focusedTaskId) {
+ navigate({ to: ".", search: { taskId: state.focusedTaskId } });
+ }
+ },
+ enter: () => {
+ const { focusedTaskId } = useBacklogBulkSelectionStore.getState();
+ if (focusedTaskId && project) {
+ navigate({
+ to: "/dashboard/workspace/$workspaceId/project/$projectId/task/$taskId",
+ params: {
+ workspaceId: project.workspaceId,
+ projectId: project.id,
+ taskId: focusedTaskId,
+ },
+ });
+ }
+ },
},
- k: () => {
- focusPrevious();
- const state = useBacklogBulkSelectionStore.getState();
- if (state.focusedTaskId) {
- navigate({ to: ".", search: { taskId: state.focusedTaskId } });
- }
- },
- Enter: () => {
- if (focusedTaskId && project) {
- navigate({
- to: "/dashboard/workspace/$workspaceId/project/$projectId/task/$taskId",
- params: {
- workspaceId: project.workspaceId,
- projectId: project.id,
- taskId: focusedTaskId,
- },
- });
- }
- },
- },
- });
+ }),
+ [focusNext, focusPrevious, navigate, project],
+ );
+ useRegisterShortcuts(keyboardShortcuts);
const sensors = useSensors(
useSensor(MouseSensor, {
@@ -281,125 +280,17 @@ function BacklogListView({
setProject(updatedProject);
};
- const toggleSection = (sectionId: string) => {
+ const toggleSection = useCallback((sectionId: string) => {
setExpandedSections((prev) => ({
...prev,
[sectionId]: !prev[sectionId],
}));
- };
+ }, []);
- function BacklogSection({
- sectionId,
- title,
- icon: IconComponent,
- tasks,
- showAddButton = false,
- }: {
- sectionId: string;
- title: string;
- icon: typeof Clock;
- tasks: Task[];
- showAddButton?: boolean;
- }) {
- const { setNodeRef } = useDroppable({
- id: sectionId,
- data: {
- type: "column",
- column: { id: sectionId, name: title },
- },
- });
-
- const showDropIndicator = activeId && overColumnId === sectionId;
-
- return (
- <div
- className={cn(
- "border-b border-border/50 transition-colors duration-150 overflow-auto",
- showDropIndicator && "border-l-4 border-l-ring bg-accent/35",
- )}
- >
- <div className="flex items-center justify-between py-2 px-4 bg-muted/60 border-b border-border/50">
- <button
- type="button"
- onClick={() => toggleSection(sectionId)}
- className="flex items-center gap-2 text-sm font-medium text-foreground hover:text-foreground transition-colors"
- >
- <ChevronRight
- className={cn(
- "w-3 h-3 transition-transform",
- expandedSections[sectionId] && "rotate-90",
- )}
- />
- <div className="flex items-center gap-2 h-4">
- <IconComponent className="w-4 h-4 flex-shrink-0 text-muted-foreground" />
- <div className="flex items-center gap-1">
- <span className="mt-1 mr-1">
- {t(`tasks:backlog.sections.${sectionId}`, {
- defaultValue: title,
- })}
- </span>
- <span className="text-xs text-muted-foreground mt-0.5">
- {tasks.length}
- </span>
- </div>
- </div>
- </button>
-
- <div className="flex items-center gap-1">
- {showAddButton && (
- <button
- type="button"
- onClick={() => {
- setIsTaskModalOpen(true);
- setActiveColumn("planned");
- }}
- className="p-1 hover:bg-accent rounded text-muted-foreground hover:text-foreground transition-colors"
- title={t("tasks:backlog.addTask")}
- >
- <Plus className="w-3 h-3" />
- </button>
- )}
- </div>
- </div>
-
- {expandedSections[sectionId] && (
- <div
- ref={setNodeRef}
- className="bg-card transition-[translate,opacity] duration-150 ease-out starting:-translate-y-1 starting:opacity-0 motion-reduce:starting:translate-y-0"
- >
- <SortableContext
- items={tasks}
- strategy={verticalListSortingStrategy}
- >
- <AnimatePresence initial={false} mode="popLayout">
- {tasks.map((task) => (
- <motion.div
- key={task.id}
- initial={{ opacity: 0 }}
- animate={{ opacity: 1 }}
- exit={{ opacity: 0 }}
- transition={{ duration: 0.15, ease: [0.23, 1, 0.32, 1] }}
- >
- <BacklogTaskRow task={task} />
- </motion.div>
- ))}
- </AnimatePresence>
- </SortableContext>
-
- {tasks.length === 0 && (
- <div className="py-6 px-4 text-center text-xs text-muted-foreground">
- {t("tasks:backlog.noTasksInSection", {
- section: t(`tasks:backlog.sections.${sectionId}`, {
- defaultValue: title,
- }).toLowerCase(),
- })}
- </div>
- )}
- </div>
- )}
- </div>
- );
- }
+ const openPlannedTaskModal = useCallback(() => {
+ setIsTaskModalOpen(true);
+ setActiveColumn("planned");
+ }, []);
if (!project) {
return null;
@@ -428,7 +319,10 @@ function BacklogListView({
title={t("tasks:backlog.sections.planned")}
icon={Clock}
tasks={plannedTasks}
- showAddButton={true}
+ isExpanded={expandedSections.planned}
+ showDropIndicator={activeId !== null && overColumnId === "planned"}
+ onToggle={toggleSection}
+ onAddTask={openPlannedTaskModal}
/>
<BacklogSection
@@ -436,6 +330,9 @@ function BacklogListView({
title={t("tasks:backlog.sections.archived")}
icon={Archive}
tasks={archivedTasks}
+ isExpanded={expandedSections.archived}
+ showDropIndicator={activeId !== null && overColumnId === "archived"}
+ onToggle={toggleSection}
/>
</div>
</div>