refactor: optimize project auto-expand logic

This commit is contained in:
Haileyesus
2026-04-25 21:49:09 +03:00
parent 360aa514f9
commit d3adc7afb8

View File

@@ -80,7 +80,7 @@ type UseSidebarControllerArgs = {
export function useSidebarController({ export function useSidebarController({
projects, projects,
selectedProject, selectedProject,
selectedSession, selectedSession: _selectedSession,
isLoading, isLoading,
isMobile, isMobile,
t, t,
@@ -133,19 +133,23 @@ export function useSidebarController({
}, [projects]); }, [projects]);
useEffect(() => { useEffect(() => {
// Expanded-project tracking is now keyed by the DB `projectId` so state // Auto-expand only when the selected project identity changes.
// survives display-name edits and other mutations. // Depending on the full `selectedProject` object (or `selectedSession`) causes
if (selectedProject) { // websocket-driven list refreshes to re-open projects users manually collapsed.
setExpandedProjects((prev) => { const selectedProjectId = selectedProject?.projectId;
if (prev.has(selectedProject.projectId)) { if (!selectedProjectId) {
return prev; return;
}
const next = new Set(prev);
next.add(selectedProject.projectId);
return next;
});
} }
}, [selectedSession, selectedProject]);
setExpandedProjects((prev) => {
if (prev.has(selectedProjectId)) {
return prev;
}
const next = new Set(prev);
next.add(selectedProjectId);
return next;
});
}, [selectedProject?.projectId]);
useEffect(() => { useEffect(() => {
if (projects.length > 0 && !isLoading) { if (projects.length > 0 && !isLoading) {