⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
fix(web): keep list and backlog collapse state per project
Tinfb1cc8f11e5f
diff --git a/apps/web/src/components/backlog-list-view/index.test.tsx b/apps/web/src/components/backlog-list-view/index.test.tsxindex 9d03de9b6..2f118cfb2 100644--- a/apps/web/src/components/backlog-list-view/index.test.tsx+++ b/apps/web/src/components/backlog-list-view/index.test.tsx@@ -113,7 +113,10 @@ beforeEach(() => {);vi.clearAllMocks();});-afterEach(cleanup);+afterEach(() => {+ cleanup();+ window.localStorage.clear();+});describe("backlog row lifecycle", () => {it("mounts each row once and preserves the other section when collapsing and expanding", () => {@@ -150,6 +153,23 @@ describe("backlog row lifecycle", () => {).toHaveLength(totalTaskCount);});+ it("keeps collapsed sections after the backlog unmounts", () => {+ const plannedToggle = () =>+ screen.getByRole("button", { name: /tasks:backlog.sections.planned/ });+ const { unmount } = render(<BacklogListView project={project} />, {+ wrapper: Providers,+ });+ fireEvent.click(plannedToggle());+ // Visiting the board unmounts the backlog.+ unmount();++ render(<BacklogListView project={project} />, { wrapper: Providers });+ expect(plannedToggle()).toHaveAttribute("aria-expanded", "false");+ expect(+ screen.getByRole("button", { name: /tasks:backlog.sections.archived/ }),+ ).toHaveAttribute("aria-expanded", "true");+ });+it("does not render the list again on selection or keyboard focus changes", () => {render(<BacklogListView project={project} />, {wrapper: Providers,diff --git a/apps/web/src/components/backlog-list-view/index.tsx b/apps/web/src/components/backlog-list-view/index.tsxindex 3cbffc847..0a0bb48af 100644--- a/apps/web/src/components/backlog-list-view/index.tsx+++ b/apps/web/src/components/backlog-list-view/index.tsx@@ -20,6 +20,7 @@ import { useTranslation } from "react-i18next";import { priorityColorsTaskCard } from "@/constants/priority-colors";import { useUpdateTask } from "@/hooks/mutations/task/use-update-task";import { useTaskViewShortcuts } from "@/components/project/task-view-keys/use-task-view-shortcuts";+import { useCollapsedSections } from "@/hooks/use-collapsed-sections";import { cn } from "@/lib/cn";import useBacklogBulkSelectionStore from "@/store/backlog-bulk-selection";import useProjectStore from "@/store/project";@@ -47,31 +48,29 @@ function BacklogListView({const clearFocus = useBacklogBulkSelectionStore((state) => state.clearFocus);const [activeId, setActiveId] = useState<UniqueIdentifier | null>(null);const [overColumnId, setOverColumnId] = useState<string | null>(null);- const [expandedSections, setExpandedSections] = useState<- Record<string, boolean>- >({- planned: true,- archived: true,- });+ const { isExpanded, toggleSection, toggleAllSections } = useCollapsedSections(+ project?.id,+ "backlog",+ );const [isTaskModalOpen, setIsTaskModalOpen] = useState(false);const [activeColumn, setActiveColumn] = useState<string | null>(null);useEffect(() => {if (project) {const visibleTaskIds: string[] = [];- if (expandedSections.planned) {+ if (isExpanded("planned")) {visibleTaskIds.push(...(project.plannedTasks || []).map((task) => task.id),);}- if (expandedSections.archived) {+ if (isExpanded("archived")) {visibleTaskIds.push(...(project.archivedTasks || []).map((task) => task.id),);}setAvailableTasks(visibleTaskIds);}- }, [project, expandedSections, setAvailableTasks]);+ }, [project, isExpanded, setAvailableTasks]);useEffect(() => {clearFocus();@@ -237,20 +236,6 @@ function BacklogListView({if (over) moveTask(active.id.toString(), over.id.toString());};- const toggleSection = useCallback((sectionId: string) => {- setExpandedSections((prev) => ({- ...prev,- [sectionId]: !prev[sectionId],- }));- }, []);-- const toggleAllSections = useCallback(() => {- setExpandedSections((prev) => {- const expand = !prev.planned && !prev.archived;- return { planned: expand, archived: expand };- });- }, []);-useTaskViewShortcuts({layout: "list",selection: useBacklogBulkSelectionStore,@@ -258,12 +243,12 @@ function BacklogListView({{id: "planned",taskIds: (project?.plannedTasks ?? []).map((task) => task.id),- collapsed: !expandedSections.planned,+ collapsed: !isExpanded("planned"),},{id: "archived",taskIds: (project?.archivedTasks ?? []).map((task) => task.id),- collapsed: !expandedSections.archived,+ collapsed: !isExpanded("archived"),},],project,@@ -271,7 +256,7 @@ function BacklogListView({canMove: !disableDragDrop,onMove: moveTask,onToggleGroup: toggleSection,- onToggleAllGroups: toggleAllSections,+ onToggleAllGroups: () => toggleAllSections(["planned", "archived"]),});const openPlannedTaskModal = useCallback(() => {@@ -311,7 +296,7 @@ function BacklogListView({title={t("tasks:backlog.sections.planned")}icon={Clock}tasks={plannedTasks}- isExpanded={expandedSections.planned}+ isExpanded={isExpanded("planned")}showDropIndicator={activeId !== null && overColumnId === "planned"}onToggle={toggleSection}onAddTask={openPlannedTaskModal}@@ -322,7 +307,7 @@ function BacklogListView({title={t("tasks:backlog.sections.archived")}icon={Archive}tasks={archivedTasks}- isExpanded={expandedSections.archived}+ isExpanded={isExpanded("archived")}showDropIndicator={activeId !== null && overColumnId === "archived"}onToggle={toggleSection}/>diff --git a/apps/web/src/components/list-view/index.test.tsx b/apps/web/src/components/list-view/index.test.tsxindex 7ed46045c..588efbb74 100644--- a/apps/web/src/components/list-view/index.test.tsx+++ b/apps/web/src/components/list-view/index.test.tsx@@ -61,6 +61,7 @@ vi.mock("../shared/modals/archive-tasks-modal", () => ({afterEach(() => {cleanup();vi.clearAllMocks();+ window.localStorage.clear();});it("disables keyboard sensors and rejects drag completion on a partial board", () => {const project = {@@ -138,3 +139,35 @@ it("blocks archive-all during pagination or errors, including an already-open coexpect(m.mutate).toHaveBeenCalledTimes(2);expect(m.setProject).toHaveBeenCalledOnce();});++it("keeps collapsed lanes per project after the list view unmounts", () => {+ const makeProject = (id: string) =>+ ({+ id,+ workspaceId: "w",+ columns: [+ { id: "todo", slug: "todo", name: "To do", tasks: [] },+ { id: "done", slug: "done", name: "Done", tasks: [] },+ ],+ plannedTasks: [],+ archivedTasks: [],+ }) as unknown as ProjectWithTasks;+ const lane = (name: string) =>+ screen.getByRole("button", { name: new RegExp(`^${name}`) });++ const { unmount } = render(<ListView project={makeProject("p")} />, {+ wrapper: Providers,+ });+ fireEvent.click(lane("To do"));+ expect(lane("To do")).toHaveAttribute("aria-expanded", "false");+ // Visiting the backlog unmounts the list view.+ unmount();++ render(<ListView project={makeProject("p")} />, { wrapper: Providers });+ expect(lane("To do")).toHaveAttribute("aria-expanded", "false");+ expect(lane("Done")).toHaveAttribute("aria-expanded", "true");+ cleanup();++ render(<ListView project={makeProject("other")} />, { wrapper: Providers });+ expect(lane("To do")).toHaveAttribute("aria-expanded", "true");+});diff --git a/apps/web/src/components/list-view/index.tsx b/apps/web/src/components/list-view/index.tsxindex 001a5330a..5f793012d 100644--- a/apps/web/src/components/list-view/index.tsx+++ b/apps/web/src/components/list-view/index.tsx@@ -20,6 +20,7 @@ import { useTranslation } from "react-i18next";import { priorityColorsTaskCard } from "@/constants/priority-colors";import { useUpdateTask } from "@/hooks/mutations/task/use-update-task";import { useTaskViewShortcuts } from "@/components/project/task-view-keys/use-task-view-shortcuts";+import { useCollapsedSections } from "@/hooks/use-collapsed-sections";import { cn } from "@/lib/cn";import { toast } from "@/lib/toast";import useBulkSelectionStore from "@/store/bulk-selection";@@ -51,17 +52,10 @@ function ListView({const { mutate: updateTask } = useUpdateTask();const [activeId, setActiveId] = useState<UniqueIdentifier | null>(null);const [overColumnId, setOverColumnId] = useState<string | null>(null);- const [expandedSections, setExpandedSections] = useState<- Record<string, boolean>- >(() => {- const sections: Record<string, boolean> = {};- if (project?.columns) {- for (const col of project.columns) {- sections[col.id] = true;- }- }- return sections;- });+ const { isExpanded, toggleSection, toggleAllSections } = useCollapsedSections(+ project.id,+ "list",+ );const [isTaskModalOpen, setIsTaskModalOpen] = useState(false);const [activeColumn, setActiveColumn] = useState<string | null>(null);const [isArchiveModalOpen, setIsArchiveModalOpen] = useState(false);@@ -73,11 +67,11 @@ function ListView({useEffect(() => {if (project?.columns) {const visibleTaskIds = project.columns- .filter((column) => expandedSections[column.id])+ .filter((column) => isExpanded(column.id)).flatMap((column) => column.tasks.map((task) => task.id));setAvailableTasks(visibleTaskIds);}- }, [project, expandedSections, setAvailableTasks]);+ }, [project, isExpanded, setAvailableTasks]);useEffect(() => {clearFocus();@@ -201,22 +195,6 @@ function ListView({if (over) moveTask(active.id.toString(), over.id.toString());};- const toggleSection = useCallback((sectionId: string) => {- setExpandedSections((prev) => ({- ...prev,- [sectionId]: !prev[sectionId],- }));- }, []);-- const toggleAllSections = useCallback(() => {- setExpandedSections((prev) => {- const expand = !project.columns.some((column) => prev[column.id]);- return Object.fromEntries(- project.columns.map((column) => [column.id, expand]),- );- });- }, [project.columns]);-useTaskViewShortcuts({layout: "list",selection: useBulkSelectionStore,@@ -224,14 +202,15 @@ function ListView({project.columns.map((column) => ({id: column.id,taskIds: column.tasks.map((task) => task.id),- collapsed: !expandedSections[column.id],+ collapsed: !isExpanded(column.id),})),project,enabled: activeId === null,canMove: !disableDragDrop,onMove: moveTask,onToggleGroup: toggleSection,- onToggleAllGroups: toggleAllSections,+ onToggleAllGroups: () =>+ toggleAllSections(project.columns.map((column) => column.id)),});const handleAddTask = useCallback((columnId: string) => {@@ -313,7 +292,7 @@ function ListView({key={column.id}column={column}projectSlug={project.slug ?? ""}- isExpanded={Boolean(expandedSections[column.id])}+ isExpanded={isExpanded(column.id)}showDropIndicator={Boolean(activeId) && overColumnId === column.id}diff --git a/apps/web/src/hooks/use-collapsed-sections.ts b/apps/web/src/hooks/use-collapsed-sections.tsnew file mode 100644index 000000000..eff62db0c--- /dev/null+++ b/apps/web/src/hooks/use-collapsed-sections.ts@@ -0,0 +1,52 @@+import { useCallback } from "react";+import { useStoredState } from "./use-stored-state";++const NONE_COLLAPSED: string[] = [];++function normalizeCollapsed(value: unknown): string[] {+ return Array.isArray(value)+ ? value.filter((id): id is string => typeof id === "string")+ : NONE_COLLAPSED;+}++// Stores collapsed ids rather than expanded ones so sections the user has+// never touched, such as a newly added column, start expanded.+export function useCollapsedSections(+ projectId: string | undefined,+ scope: "list" | "backlog",+) {+ const [collapsed, setCollapsed] = useStoredState(+ projectId ? `kaneo:${scope}-collapsed:${projectId}` : null,+ normalizeCollapsed,+ NONE_COLLAPSED,+ );++ const isExpanded = useCallback(+ (sectionId: string) => !collapsed.includes(sectionId),+ [collapsed],+ );++ const toggleSection = useCallback(+ (sectionId: string) => {+ setCollapsed((prev) =>+ prev.includes(sectionId)+ ? prev.filter((id) => id !== sectionId)+ : [...prev, sectionId],+ );+ },+ [setCollapsed],+ );++ const toggleAllSections = useCallback(+ (sectionIds: string[]) => {+ setCollapsed((prev) =>+ sectionIds.every((id) => prev.includes(id))+ ? NONE_COLLAPSED+ : sectionIds,+ );+ },+ [setCollapsed],+ );++ return { isExpanded, toggleSection, toggleAllSections };+}