fix: resolve sidebar stale state after worktree, folder, project, and session mutations (#1038)
* fix: update sidebar store after worktree creation * fix: update sidebar store after worktree removal * fix: update sidebar store with correct key in removeProjectWorktree - Fixed key mismatch in sidebar store updates for worktree removal - Removed worktrees now properly disappear from sidebar - Aligned remove path with create path key resolution * fix: resolve sidebar stale state after folder, worktree, project, and session mutations * fix: now builds * Fix worktree sidebar store key --------- Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
This commit is contained in:
committed by
GitHub
co-authored by
Bohdan Triapitsyn
parent
b62faadd15
commit
8fdc1e7e55
@@ -9,6 +9,7 @@ import { getSafeStorage } from './utils/safeStorage';
|
||||
import { useDirectoryStore } from './useDirectoryStore';
|
||||
import { streamDebugEnabled } from '@/stores/utils/streamDebug';
|
||||
import { PROJECT_COLORS } from '@/lib/projectMeta';
|
||||
import { useSessionUIStore } from '@/sync/session-ui-store';
|
||||
|
||||
/** Pick a color key that's least used among existing projects */
|
||||
const pickAutoColor = (projects: ProjectEntry[]): string => {
|
||||
@@ -399,6 +400,7 @@ export const useProjectsStore = create<ProjectsStore>()(
|
||||
return;
|
||||
}
|
||||
const current = get();
|
||||
const project = current.projects.find((p) => p.id === id);
|
||||
const nextProjects = current.projects.filter((project) => project.id !== id);
|
||||
let nextActiveId = current.activeProjectId;
|
||||
|
||||
@@ -409,6 +411,16 @@ export const useProjectsStore = create<ProjectsStore>()(
|
||||
set({ projects: nextProjects, activeProjectId: nextActiveId });
|
||||
persistProjects(nextProjects, nextActiveId);
|
||||
|
||||
// Clean up worktree entries for the removed project
|
||||
if (project) {
|
||||
const normalizedPath = project.path.replace(/\\/g, '/').replace(/\/+$/, '') || '/';
|
||||
useSessionUIStore.setState((s) => {
|
||||
const next = new Map(s.availableWorktreesByProject);
|
||||
next.delete(normalizedPath);
|
||||
return { availableWorktreesByProject: next };
|
||||
});
|
||||
}
|
||||
|
||||
if (nextActiveId) {
|
||||
const nextActive = nextProjects.find((project) => project.id === nextActiveId);
|
||||
if (nextActive) {
|
||||
|
||||
@@ -14,7 +14,7 @@ export interface SessionFolder {
|
||||
parentId?: string | null;
|
||||
}
|
||||
|
||||
type SessionFoldersMap = Record<string, SessionFolder[]>;
|
||||
export type SessionFoldersMap = Record<string, SessionFolder[]>;
|
||||
|
||||
interface SessionFoldersState {
|
||||
foldersMap: SessionFoldersMap;
|
||||
|
||||
Reference in New Issue
Block a user