mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-17 14:29:46 +02:00
Fix request duplication
This commit is contained in:
@@ -192,6 +192,7 @@ pub async fn duplicate_request(id: &str, pool: &Pool<Sqlite>) -> Result<HttpRequ
|
|||||||
let existing = get_request(id, pool)
|
let existing = get_request(id, pool)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to get request to duplicate");
|
.expect("Failed to get request to duplicate");
|
||||||
|
|
||||||
// TODO: Figure out how to make this better
|
// TODO: Figure out how to make this better
|
||||||
let b2;
|
let b2;
|
||||||
let body = match existing.body {
|
let body = match existing.body {
|
||||||
@@ -213,7 +214,7 @@ pub async fn duplicate_request(id: &str, pool: &Pool<Sqlite>) -> Result<HttpRequ
|
|||||||
existing.authentication_type,
|
existing.authentication_type,
|
||||||
existing.url.as_str(),
|
existing.url.as_str(),
|
||||||
existing.headers.0,
|
existing.headers.0,
|
||||||
existing.sort_priority,
|
existing.sort_priority + 0.001,
|
||||||
pool,
|
pool,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { useMutation } from '@tanstack/react-query';
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||||
import { invoke } from '@tauri-apps/api';
|
import { invoke } from '@tauri-apps/api';
|
||||||
|
import type { HttpRequest } from '../lib/models';
|
||||||
import { useActiveWorkspaceId } from './useActiveWorkspaceId';
|
import { useActiveWorkspaceId } from './useActiveWorkspaceId';
|
||||||
|
import { requestsQueryKey } from './useRequests';
|
||||||
import { useRoutes } from './useRoutes';
|
import { useRoutes } from './useRoutes';
|
||||||
|
|
||||||
export function useDuplicateRequest({
|
export function useDuplicateRequest({
|
||||||
@@ -12,14 +14,19 @@ export function useDuplicateRequest({
|
|||||||
}) {
|
}) {
|
||||||
const workspaceId = useActiveWorkspaceId();
|
const workspaceId = useActiveWorkspaceId();
|
||||||
const routes = useRoutes();
|
const routes = useRoutes();
|
||||||
return useMutation<string, string>({
|
const queryClient = useQueryClient();
|
||||||
|
return useMutation<HttpRequest, string>({
|
||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
if (id === null) throw new Error("Can't duplicate a null request");
|
if (id === null) throw new Error("Can't duplicate a null request");
|
||||||
return invoke('duplicate_request', { id });
|
return invoke('duplicate_request', { id });
|
||||||
},
|
},
|
||||||
onSuccess: async (newId: string) => {
|
onSuccess: async (request) => {
|
||||||
|
queryClient.setQueryData<HttpRequest[]>(
|
||||||
|
requestsQueryKey({ workspaceId: request.workspaceId }),
|
||||||
|
(requests) => [...(requests ?? []), request],
|
||||||
|
);
|
||||||
if (navigateAfter && workspaceId !== null) {
|
if (navigateAfter && workspaceId !== null) {
|
||||||
routes.navigate('request', { workspaceId, requestId: newId });
|
routes.navigate('request', { workspaceId, requestId: request.id });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user