mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-25 10:18:31 +02:00
Fix workspace/request creation race
This commit is contained in:
@@ -19,7 +19,7 @@ export function useCreateGrpcRequest() {
|
|||||||
Partial<Pick<GrpcRequest, 'name' | 'sortPriority' | 'folderId'>>
|
Partial<Pick<GrpcRequest, 'name' | 'sortPriority' | 'folderId'>>
|
||||||
>({
|
>({
|
||||||
mutationKey: ['create_grpc_request'],
|
mutationKey: ['create_grpc_request'],
|
||||||
mutationFn: (patch) => {
|
mutationFn: async (patch) => {
|
||||||
if (workspace === null) {
|
if (workspace === null) {
|
||||||
throw new Error("Cannot create grpc request when there's no active workspace");
|
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;
|
patch.folderId = patch.folderId || activeRequest?.folderId;
|
||||||
return invokeCmd('cmd_create_grpc_request', {
|
const request = await invokeCmd<GrpcRequest>('cmd_create_grpc_request', {
|
||||||
workspaceId: workspace.id,
|
workspaceId: workspace.id,
|
||||||
name: '',
|
name: '',
|
||||||
...patch,
|
...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'),
|
onSettled: () => trackEvent('grpc_request', 'create'),
|
||||||
onSuccess: async (request) => {
|
onSuccess: async (request) => {
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export function useCreateHttpRequest() {
|
|||||||
|
|
||||||
return useMutation<HttpRequest, unknown, Partial<HttpRequest>>({
|
return useMutation<HttpRequest, unknown, Partial<HttpRequest>>({
|
||||||
mutationKey: ['create_http_request'],
|
mutationKey: ['create_http_request'],
|
||||||
mutationFn: (patch = {}) => {
|
mutationFn: async (patch = {}) => {
|
||||||
if (workspace === null) {
|
if (workspace === null) {
|
||||||
throw new Error("Cannot create request when there's no active workspace");
|
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;
|
patch.folderId = patch.folderId || activeRequest?.folderId;
|
||||||
return invokeCmd('cmd_create_http_request', {
|
const request = await invokeCmd<HttpRequest>('cmd_create_http_request', {
|
||||||
request: { workspaceId: workspace.id, ...patch },
|
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'),
|
onSettled: () => trackEvent('http_request', 'create'),
|
||||||
onSuccess: async (request) => {
|
onSuccess: async (request) => {
|
||||||
|
|||||||
@@ -18,7 +18,12 @@ export function useCreateWorkspace() {
|
|||||||
placeholder: 'My Workspace',
|
placeholder: 'My Workspace',
|
||||||
confirmText: 'Create',
|
confirmText: 'Create',
|
||||||
});
|
});
|
||||||
return invokeCmd('cmd_create_workspace', { name });
|
const workspace = await invokeCmd<Workspace>('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) => {
|
onSuccess: async (workspace) => {
|
||||||
routes.navigate('workspace', { workspaceId: workspace.id });
|
routes.navigate('workspace', { workspaceId: workspace.id });
|
||||||
|
|||||||
Reference in New Issue
Block a user