@@ -2,6 +2,7 @@ import { useAuthStore } from "@features/auth/stores/authStore";
22import { useDraftStore } from "@features/message-editor/stores/draftStore" ;
33import { useSettingsStore } from "@features/settings/stores/settingsStore" ;
44import { workspaceApi } from "@features/workspace/hooks/useWorkspace" ;
5+ import type { Workspace } from "@main/services/workspace/schemas" ;
56import type { SagaResult } from "@posthog/shared" ;
67import {
78 type TaskCreationInput ,
@@ -60,6 +61,7 @@ export class TaskService {
6061 const result = await saga . run ( input ) ;
6162
6263 if ( result . success ) {
64+ this . optimisticallyUpdateWorkspaceCache ( result . data ) ;
6365 this . updateStoresOnSuccess ( result . data , input ) ;
6466 void queryClient . invalidateQueries ( {
6567 queryKey : [ [ "workspace" , "getAll" ] ] ,
@@ -124,6 +126,7 @@ export class TaskService {
124126 const result = await saga . run ( { taskId } ) ;
125127
126128 if ( result . success ) {
129+ this . optimisticallyUpdateWorkspaceCache ( result . data ) ;
127130 this . updateStoresOnSuccess ( result . data ) ;
128131 void queryClient . invalidateQueries ( {
129132 queryKey : [ [ "workspace" , "getAll" ] ] ,
@@ -151,6 +154,17 @@ export class TaskService {
151154 return result ;
152155 }
153156
157+ private optimisticallyUpdateWorkspaceCache (
158+ output : TaskCreationOutput ,
159+ ) : void {
160+ if ( ! output . workspace ) return ;
161+ const workspace = output . workspace ;
162+ queryClient . setQueriesData < Record < string , Workspace > > (
163+ { queryKey : [ [ "workspace" , "getAll" ] ] } ,
164+ ( old ) => ( { ...old , [ output . task . id ] : workspace } ) ,
165+ ) ;
166+ }
167+
154168 /**
155169 * Batch update stores after successful task creation/open.
156170 */
0 commit comments