fix(sidebar): preserve pins after partial session loads
This commit is contained in:
@@ -320,6 +320,7 @@ export const SessionSidebar: React.FC<SessionSidebarProps> = ({
|
|||||||
const liveSessions = useAllLiveSessions();
|
const liveSessions = useAllLiveSessions();
|
||||||
const isVSCode = React.useMemo(() => isVSCodeRuntime(), []);
|
const isVSCode = React.useMemo(() => isVSCodeRuntime(), []);
|
||||||
const hasLoadedGlobalSessions = useGlobalSessionsStore((state) => state.hasLoaded);
|
const hasLoadedGlobalSessions = useGlobalSessionsStore((state) => state.hasLoaded);
|
||||||
|
const hasAuthoritativeGlobalSessions = useGlobalSessionsStore((state) => state.status === 'ready');
|
||||||
const globalActiveSessions = useGlobalSessionsStore((state) => state.activeSessions);
|
const globalActiveSessions = useGlobalSessionsStore((state) => state.activeSessions);
|
||||||
const archivedSessions = useGlobalSessionsStore((state) => state.archivedSessions);
|
const archivedSessions = useGlobalSessionsStore((state) => state.archivedSessions);
|
||||||
const currentSessionId = useSessionUIStore((state) => state.currentSessionId);
|
const currentSessionId = useSessionUIStore((state) => state.currentSessionId);
|
||||||
@@ -539,7 +540,7 @@ export const SessionSidebar: React.FC<SessionSidebarProps> = ({
|
|||||||
|
|
||||||
const { scheduleCollapsedProjectsPersist } = useSidebarPersistence({
|
const { scheduleCollapsedProjectsPersist } = useSidebarPersistence({
|
||||||
isVSCode,
|
isVSCode,
|
||||||
hasLoadedGlobalSessions,
|
hasAuthoritativeGlobalSessions,
|
||||||
safeStorage,
|
safeStorage,
|
||||||
keys: {
|
keys: {
|
||||||
sessionExpanded: SESSION_EXPANDED_STORAGE_KEY,
|
sessionExpanded: SESSION_EXPANDED_STORAGE_KEY,
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ const LEGACY_EXPANSION_CONTEXT_PREFIXES = [
|
|||||||
|
|
||||||
type Args = {
|
type Args = {
|
||||||
isVSCode: boolean;
|
isVSCode: boolean;
|
||||||
hasLoadedGlobalSessions: boolean;
|
hasAuthoritativeGlobalSessions: boolean;
|
||||||
safeStorage: SafeStorageLike;
|
safeStorage: SafeStorageLike;
|
||||||
keys: Keys;
|
keys: Keys;
|
||||||
sessions: Session[];
|
sessions: Session[];
|
||||||
@@ -49,7 +49,7 @@ type Args = {
|
|||||||
export const useSidebarPersistence = (args: Args) => {
|
export const useSidebarPersistence = (args: Args) => {
|
||||||
const {
|
const {
|
||||||
isVSCode,
|
isVSCode,
|
||||||
hasLoadedGlobalSessions,
|
hasAuthoritativeGlobalSessions,
|
||||||
safeStorage,
|
safeStorage,
|
||||||
keys,
|
keys,
|
||||||
sessions,
|
sessions,
|
||||||
@@ -151,14 +151,14 @@ export const useSidebarPersistence = (args: Args) => {
|
|||||||
}, [keys.projectCollapse, keys.sessionExpanded, keys.sessionExpandedLegacy, safeStorage, setCollapsedProjects, setExpandedParents]);
|
}, [keys.projectCollapse, keys.sessionExpanded, keys.sessionExpandedLegacy, safeStorage, setCollapsedProjects, setExpandedParents]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!hasLoadedGlobalSessions) {
|
if (!hasAuthoritativeGlobalSessions) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setPinnedSessionIds((prev) => {
|
setPinnedSessionIds((prev) => {
|
||||||
return prunePinnedSessionIds(sessions, prev);
|
return prunePinnedSessionIds(sessions, prev);
|
||||||
});
|
});
|
||||||
}, [hasLoadedGlobalSessions, sessions, setPinnedSessionIds]);
|
}, [hasAuthoritativeGlobalSessions, sessions, setPinnedSessionIds]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -420,7 +420,10 @@ export const useGlobalSessionsStore = create<GlobalSessionsState>((set, get) =>
|
|||||||
// instance — drop it.
|
// instance — drop it.
|
||||||
return { activeSessions: [], archivedSessions: [] };
|
return { activeSessions: [], archivedSessions: [] };
|
||||||
}
|
}
|
||||||
set((state) => applySnapshot(state, nextActiveSessions, nextArchivedSessions, 'ready'));
|
const status = activeResult.status === 'fulfilled' && archivedResult.status === 'fulfilled'
|
||||||
|
? 'ready'
|
||||||
|
: 'error';
|
||||||
|
set((state) => applySnapshot(state, nextActiveSessions, nextArchivedSessions, status));
|
||||||
return { activeSessions: nextActiveSessions, archivedSessions: nextArchivedSessions };
|
return { activeSessions: nextActiveSessions, archivedSessions: nextArchivedSessions };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (generation !== loadGeneration) {
|
if (generation !== loadGeneration) {
|
||||||
|
|||||||
Reference in New Issue
Block a user