Keep collapsed projects across sidebar refreshes

Sidebar project lists can be partial while hosts or workspace data are changing. Preserve collapsed preferences instead of treating a temporarily missing project as a request to expand it.
This commit is contained in:
Mohamed Boudra
2026-06-20 22:26:17 +07:00
parent 25252d1b86
commit 7f74853174
3 changed files with 106 additions and 20 deletions
@@ -1,13 +1,10 @@
import { useEffect, useMemo } from "react";
import { useMemo } from "react";
import type { SidebarProjectEntry } from "@/hooks/use-sidebar-workspaces-list";
import { buildSidebarShortcutModel } from "@/utils/sidebar-shortcuts";
import { useSidebarCollapsedSectionsStore } from "@/stores/sidebar-collapsed-sections-store";
export function useSidebarShortcutModel(input: {
projects: SidebarProjectEntry[];
isInitialLoad: boolean;
}) {
const { projects, isInitialLoad } = input;
export function useSidebarShortcutModel(input: { projects: SidebarProjectEntry[] }) {
const { projects } = input;
const collapsedProjectKeys = useSidebarCollapsedSectionsStore(
(state) => state.collapsedProjectKeys,
);
@@ -27,19 +24,6 @@ export function useSidebarShortcutModel(input: {
[collapsedProjectKeys, projects],
);
useEffect(() => {
if (isInitialLoad || projects.length === 0) {
return;
}
const projectKeys = new Set(projects.map((project) => project.projectKey));
for (const key of collapsedProjectKeys) {
if (!projectKeys.has(key)) {
setProjectCollapsed(key, false);
}
}
}, [collapsedProjectKeys, isInitialLoad, projects, setProjectCollapsed]);
return {
collapsedProjectKeys,
shortcutIndexByWorkspaceKey: shortcutModel.shortcutIndexByWorkspaceKey,