Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions apps/code/src/renderer/features/tasks/hooks/useArchiveTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,21 @@ export async function archiveTaskImperative(
}
}

const terminalStatesSnapshot = Object.fromEntries(
Object.entries(useTerminalStore.getState().terminalStates).filter(
([key]) => key === taskId || key.startsWith(`${taskId}-`),
),
);
const commandCenterState = useCommandCenterStore.getState();
const commandCenterIndex = commandCenterState.cells.indexOf(taskId);
const wasActiveInCommandCenter = commandCenterState.activeTaskId === taskId;

pinnedTasksApi.unpin(taskId);
useTerminalStore.getState().clearTerminalStatesForTask(taskId);
useCommandCenterStore.getState().removeTaskById(taskId);

await queryClient.cancelQueries(trpc.archive.pathFilter());

queryClient.setQueryData<string[]>(
trpc.archive.archivedTaskIds.queryKey(),
(old) => (old ? [...old, taskId] : [taskId]),
Expand Down Expand Up @@ -87,6 +98,20 @@ export async function archiveTaskImperative(
if (wasPinned) {
pinnedTasksApi.togglePin(taskId);
}
if (Object.keys(terminalStatesSnapshot).length > 0) {
useTerminalStore.setState((s) => ({
terminalStates: { ...s.terminalStates, ...terminalStatesSnapshot },
}));
}
if (commandCenterIndex !== -1) {
useCommandCenterStore.setState((s) => {
const cells = [...s.cells];
cells[commandCenterIndex] = taskId;
return wasActiveInCommandCenter
? { cells, activeTaskId: taskId }
: { cells };
});
}
Comment thread
richardsolomou marked this conversation as resolved.

throw error;
}
Expand Down
Loading