Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions crates/cowork-gui/src/hooks/useAppEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,25 +377,25 @@ export function useAppEvents(userInput: string, setUserInput: (input: string) =>
}),

// Project events
listen('project_loaded', () => {
listen('project_loaded', async () => {
setProcessing(false);
setCurrentAgent(null);
setInputRequest(null);
clearMessages();
setCurrentIteration(null);
await loadProject();
setActiveView('iterations');
loadProject();
message.success('Project loaded');
}),

listen('project_initialized', () => {
listen('project_initialized', async () => {
setProcessing(false);
setCurrentAgent(null);
setInputRequest(null);
clearMessages();
setCurrentIteration(null);
await loadProject();
setActiveView('iterations');
loadProject();
message.success('Project initialized');
}),

Expand Down
28 changes: 15 additions & 13 deletions crates/cowork-gui/src/hooks/useIterationActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useCallback } from 'react';
import { App as AntApp } from 'antd';
import { useProjectStore, useAgentStore, useUIStore } from '../stores';
import API from '../api';
import type { Iteration } from '../stores';

/**
* Hook for handling iteration-related actions
Expand All @@ -12,7 +11,7 @@ export function useIterationActions() {
const { message } = AntApp.useApp();

// Project store
const { iterations, currentIteration, setCurrentIteration, setIsExecuting } = useProjectStore();
const { currentIteration, setCurrentIteration, setIsExecuting } = useProjectStore();

// Agent store
const { setProcessing } = useAgentStore();
Expand All @@ -22,23 +21,26 @@ export function useIterationActions() {

/**
* Handle selecting an iteration
* Directly fetches iteration data via API without depending on local iterations array
*/
const handleSelectIteration = useCallback(
(iterationId: string) => {
const iteration = iterations.find((i: Iteration) => i.id === iterationId);
if (iteration) {
async (iterationId: string) => {
try {
const { currentIteration, isExecuting } = useProjectStore.getState();
API.iteration.get(iterationId).then((full) => {
if (isExecuting && currentIteration?.id === iterationId) {
setCurrentIteration({ ...full, status: currentIteration.status });
} else {
setCurrentIteration(full);
}
});
const fullIteration = await API.iteration.get(iterationId);

if (isExecuting && currentIteration?.id === iterationId) {
setCurrentIteration({ ...fullIteration, status: currentIteration.status });
} else {
setCurrentIteration(fullIteration);
}
setActiveView('chat');
} catch (error) {
console.error('Failed to load iteration:', error);
message.error('Failed to load iteration: ' + error);
}
},
[iterations, setCurrentIteration, setActiveView]
[setCurrentIteration, setActiveView, message]
);

/**
Expand Down
15 changes: 12 additions & 3 deletions crates/cowork-gui/src/stores/projectStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ interface ProjectState {
currentIteration: Iteration | null;
loading: boolean;
isExecuting: boolean;
iterationsLoaded: boolean;

loadProject: () => Promise<void>;
loadIterations: () => Promise<void>;
setCurrentIteration: (iteration: Iteration | null) => void;
updateCurrentIterationStatus: (status: string) => void;
setIsExecuting: (executing: boolean) => void;
setIterationsLoaded: (loaded: boolean) => void;
clearProject: () => void;
}

Expand All @@ -56,6 +58,7 @@ export const useProjectStore = create<ProjectState>((set, get) => ({
currentIteration: null,
loading: false,
isExecuting: false,
iterationsLoaded: false,

loadProject: async () => {
try {
Expand All @@ -65,7 +68,7 @@ export const useProjectStore = create<ProjectState>((set, get) => ({

if (project) {
const iterations = await API.iteration.list();
set({ iterations: iterations || [] });
set({ iterations: iterations || [], iterationsLoaded: true });

const { currentIteration, isExecuting } = get();
if (currentIteration) {
Expand All @@ -88,16 +91,17 @@ export const useProjectStore = create<ProjectState>((set, get) => ({
}
} catch (error) {
console.error('Failed to load project:', error);
set({ loading: false });
set({ loading: false, iterationsLoaded: false });
}
},

loadIterations: async () => {
try {
const iterations = await API.iteration.list();
set({ iterations: iterations || [] });
set({ iterations: iterations || [], iterationsLoaded: true });
} catch (error) {
console.error('Failed to load iterations:', error);
set({ iterationsLoaded: false });
}
},

Expand All @@ -116,12 +120,17 @@ export const useProjectStore = create<ProjectState>((set, get) => ({
set({ isExecuting: executing });
},

setIterationsLoaded: (loaded) => {
set({ iterationsLoaded: loaded });
},

clearProject: () => {
set({
project: null,
iterations: [],
currentIteration: null,
isExecuting: false,
iterationsLoaded: false,
});
},
}));
Loading