diff --git a/src-web/hooks/useCreateGrpcRequest.ts b/src-web/hooks/useCreateGrpcRequest.ts index 4a9f4d2d..fdc177bb 100644 --- a/src-web/hooks/useCreateGrpcRequest.ts +++ b/src-web/hooks/useCreateGrpcRequest.ts @@ -19,7 +19,7 @@ export function useCreateGrpcRequest() { Partial> >({ mutationKey: ['create_grpc_request'], - mutationFn: (patch) => { + mutationFn: async (patch) => { if (workspace === null) { throw new Error("Cannot create grpc request when there's no active workspace"); } @@ -33,11 +33,16 @@ export function useCreateGrpcRequest() { } } patch.folderId = patch.folderId || activeRequest?.folderId; - return invokeCmd('cmd_create_grpc_request', { + const request = await invokeCmd('cmd_create_grpc_request', { workspaceId: workspace.id, name: '', ...patch, }); + + // Give some time for the workspace to sync to the local store + await new Promise((resolve) => setTimeout(resolve, 100)); + + return request; }, onSettled: () => trackEvent('grpc_request', 'create'), onSuccess: async (request) => { diff --git a/src-web/hooks/useCreateHttpRequest.ts b/src-web/hooks/useCreateHttpRequest.ts index 2fabe999..13693895 100644 --- a/src-web/hooks/useCreateHttpRequest.ts +++ b/src-web/hooks/useCreateHttpRequest.ts @@ -15,7 +15,7 @@ export function useCreateHttpRequest() { return useMutation>({ mutationKey: ['create_http_request'], - mutationFn: (patch = {}) => { + mutationFn: async (patch = {}) => { if (workspace === null) { throw new Error("Cannot create request when there's no active workspace"); } @@ -29,9 +29,14 @@ export function useCreateHttpRequest() { } } patch.folderId = patch.folderId || activeRequest?.folderId; - return invokeCmd('cmd_create_http_request', { + const request = await invokeCmd('cmd_create_http_request', { request: { workspaceId: workspace.id, ...patch }, }); + + // Give some time for the workspace to sync to the local store + await new Promise((resolve) => setTimeout(resolve, 100)); + + return request; }, onSettled: () => trackEvent('http_request', 'create'), onSuccess: async (request) => { diff --git a/src-web/hooks/useCreateWorkspace.ts b/src-web/hooks/useCreateWorkspace.ts index 61ebf3d1..7b8c8179 100644 --- a/src-web/hooks/useCreateWorkspace.ts +++ b/src-web/hooks/useCreateWorkspace.ts @@ -18,7 +18,12 @@ export function useCreateWorkspace() { placeholder: 'My Workspace', confirmText: 'Create', }); - return invokeCmd('cmd_create_workspace', { name }); + const workspace = await invokeCmd('cmd_create_workspace', { name }); + + // Give some time for the workspace to sync to the local store + await new Promise((resolve) => setTimeout(resolve, 100)); + + return workspace; }, onSuccess: async (workspace) => { routes.navigate('workspace', { workspaceId: workspace.id });