Fix workspace/request creation race

This commit is contained in:
Gregory Schier
2024-10-22 14:27:12 -07:00
parent 94f8949ca2
commit 5de50c70c6
3 changed files with 20 additions and 5 deletions

View File

@@ -19,7 +19,7 @@ export function useCreateGrpcRequest() {
Partial<Pick<GrpcRequest, 'name' | 'sortPriority' | 'folderId'>>
>({
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<GrpcRequest>('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) => {