mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-18 07:24:07 +01:00
Switch to useMutation in some places
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { useFolders } from '../hooks/useFolders';
|
||||
import { useUpdateAnyFolder } from '../hooks/useUpdateAnyFolder';
|
||||
import { Banner } from './core/Banner';
|
||||
import { PlainInput } from './core/PlainInput';
|
||||
import { VStack } from './core/Stacks';
|
||||
import { MarkdownEditor } from './MarkdownEditor';
|
||||
@@ -10,7 +9,7 @@ interface Props {
|
||||
}
|
||||
|
||||
export function FolderSettingsDialog({ folderId }: Props) {
|
||||
const updateFolder = useUpdateAnyFolder();
|
||||
const { mutate: updateFolder } = useUpdateAnyFolder();
|
||||
const folders = useFolders();
|
||||
const folder = folders.find((f) => f.id === folderId);
|
||||
|
||||
@@ -18,13 +17,12 @@ export function FolderSettingsDialog({ folderId }: Props) {
|
||||
|
||||
return (
|
||||
<VStack space={3} className="pb-3">
|
||||
{updateFolder.error != null && <Banner color="danger">{String(updateFolder.error)}</Banner>}
|
||||
<PlainInput
|
||||
label="Folder Name"
|
||||
defaultValue={folder.name}
|
||||
onChange={(name) => {
|
||||
if (folderId == null) return;
|
||||
updateFolder.mutate({ id: folderId, update: (folder) => ({ ...folder, name }) });
|
||||
updateFolder({ id: folderId, update: (folder) => ({ ...folder, name }) });
|
||||
}}
|
||||
/>
|
||||
|
||||
@@ -35,7 +33,7 @@ export function FolderSettingsDialog({ folderId }: Props) {
|
||||
defaultValue={folder.description}
|
||||
onChange={(description) => {
|
||||
if (folderId == null) return;
|
||||
updateFolder.mutate({
|
||||
updateFolder({
|
||||
id: folderId,
|
||||
update: (folder) => ({ ...folder, description }),
|
||||
});
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { useUpdateWorkspace } from '../hooks/useUpdateWorkspace';
|
||||
import { useWorkspaces } from '../hooks/useWorkspaces';
|
||||
import { Banner } from './core/Banner';
|
||||
import { PlainInput } from './core/PlainInput';
|
||||
import { VStack } from './core/Stacks';
|
||||
import { MarkdownEditor } from './MarkdownEditor';
|
||||
@@ -18,9 +17,6 @@ export function WorkspaceSettingsDialog({ workspaceId }: Props) {
|
||||
|
||||
return (
|
||||
<VStack space={3} className="pb-3">
|
||||
{updateWorkspace.error != null && (
|
||||
<Banner color="danger">{String(updateWorkspace.error)}</Banner>
|
||||
)}
|
||||
<PlainInput
|
||||
label="Workspace Name"
|
||||
defaultValue={workspace.name}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import { event } from '@tauri-apps/api';
|
||||
import { trackEvent } from '../lib/analytics';
|
||||
|
||||
export function useCancelHttpResponse(id: string | null) {
|
||||
return useMutation<void>({
|
||||
return useFastMutation<void>({
|
||||
mutationKey: ['cancel_http_response', id],
|
||||
mutationFn: () => event.emit(`cancel_http_response_${id}`),
|
||||
onSettled: () => trackEvent('http_response', 'cancel'),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { InlineCode } from '../components/core/InlineCode';
|
||||
import { minPromiseMillis } from '../lib/minPromiseMillis';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { HttpResponse } from '@yaakapp-internal/models';
|
||||
import { useCopy } from './useCopy';
|
||||
import { getResponseBodyText } from '../lib/responseBody';
|
||||
|
||||
export function useCopyHttpResponse(response: HttpResponse) {
|
||||
const copy = useCopy();
|
||||
return useMutation({
|
||||
return useFastMutation({
|
||||
mutationKey: ['copy_http_response'],
|
||||
async mutationFn() {
|
||||
const body = await getResponseBodyText(response);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { CookieJar } from '@yaakapp-internal/models';
|
||||
import {useSetAtom} from "jotai";
|
||||
import { trackEvent } from '../lib/analytics';
|
||||
@@ -13,7 +13,7 @@ export function useCreateCookieJar() {
|
||||
const prompt = usePrompt();
|
||||
const setCookieJars = useSetAtom(cookieJarsAtom);
|
||||
|
||||
return useMutation<CookieJar | null>({
|
||||
return useFastMutation<CookieJar | null>({
|
||||
mutationKey: ['create_cookie_jar'],
|
||||
mutationFn: async () => {
|
||||
if (workspace === null) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { Environment } from '@yaakapp-internal/models';
|
||||
import {useSetAtom} from "jotai";
|
||||
import { trackEvent } from '../lib/analytics';
|
||||
@@ -15,7 +15,7 @@ export function useCreateEnvironment() {
|
||||
const workspace = useActiveWorkspace();
|
||||
const setEnvironments = useSetAtom(environmentsAtom);
|
||||
|
||||
return useMutation<Environment | null, unknown, void>({
|
||||
return useFastMutation<Environment | null, unknown, void>({
|
||||
mutationKey: ['create_environment'],
|
||||
mutationFn: async () => {
|
||||
const name = await prompt({
|
||||
@@ -42,7 +42,7 @@ export function useCreateEnvironment() {
|
||||
// Optimistic update
|
||||
setEnvironments(updateModelList(environment));
|
||||
|
||||
setActiveEnvironmentId(environment.id);
|
||||
await setActiveEnvironmentId(environment.id);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { Folder } from '@yaakapp-internal/models';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { trackEvent } from '../lib/analytics';
|
||||
@@ -13,7 +13,7 @@ export function useCreateFolder() {
|
||||
const prompt = usePrompt();
|
||||
const setFolders = useSetAtom(foldersAtom);
|
||||
|
||||
return useMutation<
|
||||
return useFastMutation<
|
||||
Folder | null,
|
||||
unknown,
|
||||
Partial<Pick<Folder, 'name' | 'sortPriority' | 'folderId'>>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { GrpcRequest } from '@yaakapp-internal/models';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { trackEvent } from '../lib/analytics';
|
||||
@@ -14,7 +14,7 @@ export function useCreateGrpcRequest() {
|
||||
const workspace = useActiveWorkspace();
|
||||
const setGrpcRequests = useSetAtom(grpcRequestsAtom);
|
||||
|
||||
return useMutation<
|
||||
return useFastMutation<
|
||||
GrpcRequest,
|
||||
unknown,
|
||||
Partial<Pick<GrpcRequest, 'name' | 'sortPriority' | 'folderId'>>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { HttpRequest } from '@yaakapp-internal/models';
|
||||
import { useSetAtom } from 'jotai/index';
|
||||
import { trackEvent } from '../lib/analytics';
|
||||
@@ -14,7 +14,7 @@ export function useCreateHttpRequest() {
|
||||
const activeWorkspace = useActiveWorkspace();
|
||||
const setHttpRequests = useSetAtom(httpRequestsAtom);
|
||||
|
||||
return useMutation<HttpRequest, unknown, Partial<HttpRequest>>({
|
||||
return useFastMutation<HttpRequest, unknown, Partial<HttpRequest>>({
|
||||
mutationKey: ['create_http_request'],
|
||||
mutationFn: async (patch = {}) => {
|
||||
const activeRequest = getActiveRequest();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { Workspace } from '@yaakapp-internal/models';
|
||||
import { useSetAtom } from 'jotai/index';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
@@ -12,7 +12,7 @@ export function useCreateWorkspace() {
|
||||
const prompt = usePrompt();
|
||||
const setWorkspaces = useSetAtom(workspacesAtom);
|
||||
|
||||
return useMutation<Workspace | null, void, void>({
|
||||
return useFastMutation<Workspace | null, void, void>({
|
||||
mutationKey: ['create_workspace'],
|
||||
mutationFn: async () => {
|
||||
const name = await prompt({
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { GrpcRequest } from '@yaakapp-internal/models';
|
||||
import {useSetAtom} from "jotai";
|
||||
import { InlineCode } from '../components/core/InlineCode';
|
||||
@@ -14,7 +14,7 @@ export function useDeleteAnyGrpcRequest() {
|
||||
const confirm = useConfirm();
|
||||
const setGrpcRequests = useSetAtom(grpcRequestsAtom);
|
||||
|
||||
return useMutation<GrpcRequest | null, string, string>({
|
||||
return useFastMutation<GrpcRequest | null, string, string>({
|
||||
mutationKey: ['delete_any_grpc_request'],
|
||||
mutationFn: async (id) => {
|
||||
const request = await getGrpcRequest(id);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { HttpRequest } from '@yaakapp-internal/models';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { InlineCode } from '../components/core/InlineCode';
|
||||
@@ -14,7 +14,7 @@ export function useDeleteAnyHttpRequest() {
|
||||
const confirm = useConfirm();
|
||||
const setHttpRequests = useSetAtom(httpRequestsAtom);
|
||||
|
||||
return useMutation<HttpRequest | null, string, string>({
|
||||
return useFastMutation<HttpRequest | null, string, string>({
|
||||
mutationKey: ['delete_any_http_request'],
|
||||
mutationFn: async (id) => {
|
||||
const request = await getHttpRequest(id);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { CookieJar } from '@yaakapp-internal/models';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { InlineCode } from '../components/core/InlineCode';
|
||||
@@ -12,7 +12,7 @@ export function useDeleteCookieJar(cookieJar: CookieJar | null) {
|
||||
const confirm = useConfirm();
|
||||
const setCookieJars = useSetAtom(cookieJarsAtom);
|
||||
|
||||
return useMutation<CookieJar | null, string>({
|
||||
return useFastMutation<CookieJar | null, string>({
|
||||
mutationKey: ['delete_cookie_jar', cookieJar?.id],
|
||||
mutationFn: async () => {
|
||||
const confirmed = await confirm({
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { Environment } from '@yaakapp-internal/models';
|
||||
import {useSetAtom} from "jotai";
|
||||
import { InlineCode } from '../components/core/InlineCode';
|
||||
@@ -12,7 +12,7 @@ export function useDeleteEnvironment(environment: Environment | null) {
|
||||
const confirm = useConfirm();
|
||||
const setEnvironments = useSetAtom(environmentsAtom);
|
||||
|
||||
return useMutation<Environment | null, string>({
|
||||
return useFastMutation<Environment | null, string>({
|
||||
mutationKey: ['delete_environment', environment?.id],
|
||||
mutationFn: async () => {
|
||||
const confirmed = await confirm({
|
||||
|
||||
@@ -7,13 +7,13 @@ import { invokeCmd } from '../lib/tauri';
|
||||
import { useConfirm } from './useConfirm';
|
||||
import { foldersAtom } from './useFolders';
|
||||
import { removeModelById } from './useSyncModelStores';
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
|
||||
export function useDeleteFolder(id: string | null) {
|
||||
const confirm = useConfirm();
|
||||
const setFolders = useSetAtom(foldersAtom);
|
||||
|
||||
return useMutation<Folder | null, string>({
|
||||
return useFastMutation<Folder | null, string>({
|
||||
mutationKey: ['delete_folder', id],
|
||||
mutationFn: async () => {
|
||||
const folder = await getFolder(id);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { GrpcConnection } from '@yaakapp-internal/models';
|
||||
import {useSetAtom} from "jotai";
|
||||
import { trackEvent } from '../lib/analytics';
|
||||
@@ -8,7 +8,7 @@ import {removeModelById} from "./useSyncModelStores";
|
||||
|
||||
export function useDeleteGrpcConnection(id: string | null) {
|
||||
const setGrpcConnections = useSetAtom(grpcConnectionsAtom);
|
||||
return useMutation<GrpcConnection>({
|
||||
return useFastMutation<GrpcConnection>({
|
||||
mutationKey: ['delete_grpc_connection', id],
|
||||
mutationFn: async () => {
|
||||
return await invokeCmd('cmd_delete_grpc_connection', { id: id });
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { trackEvent } from '../lib/analytics';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
@@ -6,7 +6,7 @@ import { grpcConnectionsAtom } from './useGrpcConnections';
|
||||
|
||||
export function useDeleteGrpcConnections(requestId?: string) {
|
||||
const setGrpcConnections = useSetAtom(grpcConnectionsAtom);
|
||||
return useMutation({
|
||||
return useFastMutation({
|
||||
mutationKey: ['delete_grpc_connections', requestId],
|
||||
mutationFn: async () => {
|
||||
if (requestId === undefined) return;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { HttpResponse } from '@yaakapp-internal/models';
|
||||
import {useSetAtom} from "jotai";
|
||||
import { trackEvent } from '../lib/analytics';
|
||||
@@ -8,7 +8,7 @@ import {removeModelById} from "./useSyncModelStores";
|
||||
|
||||
export function useDeleteHttpResponse(id: string | null) {
|
||||
const setHttpResponses = useSetAtom(httpResponsesAtom);
|
||||
return useMutation<HttpResponse>({
|
||||
return useFastMutation<HttpResponse>({
|
||||
mutationKey: ['delete_http_response', id],
|
||||
mutationFn: async () => {
|
||||
return await invokeCmd('cmd_delete_http_response', { id: id });
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { trackEvent } from '../lib/analytics';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
@@ -6,7 +6,7 @@ import { httpResponsesAtom } from './useHttpResponses';
|
||||
|
||||
export function useDeleteHttpResponses(requestId?: string) {
|
||||
const setHttpResponses = useSetAtom(httpResponsesAtom);
|
||||
return useMutation({
|
||||
return useFastMutation({
|
||||
mutationKey: ['delete_http_responses', requestId],
|
||||
mutationFn: async () => {
|
||||
if (requestId === undefined) return;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { useDeleteAnyGrpcRequest } from './useDeleteAnyGrpcRequest';
|
||||
import { useDeleteAnyHttpRequest } from './useDeleteAnyHttpRequest';
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
|
||||
export function useDeleteRequest(id: string | null) {
|
||||
const deleteAnyHttpRequest = useDeleteAnyHttpRequest();
|
||||
const deleteAnyGrpcRequest = useDeleteAnyGrpcRequest();
|
||||
|
||||
return useMutation<void, string>({
|
||||
return useFastMutation<void, string>({
|
||||
mutationKey: ['delete_request', id],
|
||||
mutationFn: async () => {
|
||||
if (id == null) return;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import { useSetAtom } from 'jotai/index';
|
||||
import { count } from '../lib/pluralize';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
@@ -20,7 +20,7 @@ export function useDeleteSendHistory() {
|
||||
grpcConnections.length > 0 ? count('Grpc Connection', grpcConnections.length) : null,
|
||||
].filter((l) => l != null);
|
||||
|
||||
return useMutation({
|
||||
return useFastMutation({
|
||||
mutationKey: ['delete_send_history'],
|
||||
mutationFn: async () => {
|
||||
if (labels.length === 0) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { Workspace } from '@yaakapp-internal/models';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { InlineCode } from '../components/core/InlineCode';
|
||||
@@ -16,7 +16,7 @@ export function useDeleteWorkspace(workspace: Workspace | null) {
|
||||
const confirm = useConfirm();
|
||||
const setWorkspaces = useSetAtom(workspacesAtom);
|
||||
|
||||
return useMutation<Workspace | null, string>({
|
||||
return useFastMutation<Workspace | null, string>({
|
||||
mutationKey: ['delete_workspace', workspace?.id],
|
||||
mutationFn: async () => {
|
||||
const confirmed = await confirm({
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import { trackEvent } from '../lib/analytics';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
|
||||
export function useDuplicateFolder(id: string) {
|
||||
return useMutation<void, string>({
|
||||
return useFastMutation<void, string>({
|
||||
mutationKey: ['duplicate_folder', id],
|
||||
mutationFn: () => invokeCmd('cmd_duplicate_folder', { id }),
|
||||
onSettled: () => trackEvent('folder', 'duplicate'),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { GrpcRequest } from '@yaakapp-internal/models';
|
||||
import { trackEvent } from '../lib/analytics';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
@@ -13,7 +13,7 @@ export function useDuplicateGrpcRequest({
|
||||
id: string | null;
|
||||
navigateAfter: boolean;
|
||||
}) {
|
||||
return useMutation<GrpcRequest, string>({
|
||||
return useFastMutation<GrpcRequest, string>({
|
||||
mutationKey: ['duplicate_grpc_request', id],
|
||||
mutationFn: async () => {
|
||||
if (id === null) throw new Error("Can't duplicate a null grpc request");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { HttpRequest } from '@yaakapp-internal/models';
|
||||
import { trackEvent } from '../lib/analytics';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
@@ -12,7 +12,7 @@ export function useDuplicateHttpRequest({
|
||||
id: string | null;
|
||||
navigateAfter: boolean;
|
||||
}) {
|
||||
return useMutation<HttpRequest, string>({
|
||||
return useFastMutation<HttpRequest, string>({
|
||||
mutationKey: ['duplicate_http_request', id],
|
||||
mutationFn: async () => {
|
||||
if (id === null) throw new Error("Can't duplicate a null request");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import { useDialog } from '../components/DialogContext';
|
||||
import { ExportDataDialog } from '../components/ExportDataDialog';
|
||||
import { useActiveWorkspace } from './useActiveWorkspace';
|
||||
@@ -13,7 +13,7 @@ export function useExportData() {
|
||||
const dialog = useDialog();
|
||||
const toast = useToast();
|
||||
|
||||
return useMutation({
|
||||
return useFastMutation({
|
||||
mutationKey: ['export_data'],
|
||||
onError: (err: string) => {
|
||||
alert({ id: 'export-failed', title: 'Export Failed', body: err });
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
import type { MutationKey } from '@tanstack/react-query';
|
||||
import { useCallback } from 'react';
|
||||
|
||||
export function useMutation<TData = unknown, TError = unknown, TVariables = void>({
|
||||
export function useFastMutation<TData = unknown, TError = unknown, TVariables = void>({
|
||||
mutationKey,
|
||||
mutationFn,
|
||||
onSuccess,
|
||||
onError,
|
||||
onSettled,
|
||||
}: {
|
||||
mutationKey: MutationKey;
|
||||
mutationFn: (vars: TVariables) => Promise<TData>;
|
||||
onSettled?: () => void;
|
||||
onError?: (err: TError) => void;
|
||||
onSuccess?: (data: TData) => void;
|
||||
}) {
|
||||
const mutateAsync = useCallback(
|
||||
@@ -17,9 +19,11 @@ export function useMutation<TData = unknown, TError = unknown, TVariables = void
|
||||
try {
|
||||
const data = await mutationFn(variables);
|
||||
onSuccess?.(data);
|
||||
return data;
|
||||
} catch (err: unknown) {
|
||||
const e = err as TError;
|
||||
console.log('MUTATION FAILED', mutationKey, e);
|
||||
onError?.(e);
|
||||
} finally {
|
||||
onSettled?.();
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { HttpRequest } from '@yaakapp-internal/models';
|
||||
import { useToast } from '../components/ToastContext';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
@@ -14,7 +14,7 @@ export function useImportCurl() {
|
||||
const { wasUpdatedExternally } = useRequestUpdateKey(null);
|
||||
const toast = useToast();
|
||||
|
||||
return useMutation({
|
||||
return useFastMutation({
|
||||
mutationKey: ['import_curl'],
|
||||
mutationFn: async ({
|
||||
overwriteRequestId,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type {
|
||||
Environment,
|
||||
Folder,
|
||||
@@ -75,7 +75,7 @@ export function useImportData() {
|
||||
return true;
|
||||
};
|
||||
|
||||
return useMutation({
|
||||
return useFastMutation({
|
||||
mutationKey: ['import_data'],
|
||||
onError: (err: string) => {
|
||||
alert({
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { HttpUrlParameter } from '@yaakapp-internal/models';
|
||||
import { useToast } from '../components/ToastContext';
|
||||
import { pluralize } from '../lib/pluralize';
|
||||
@@ -11,7 +11,7 @@ export function useImportQuerystring(requestId: string) {
|
||||
const toast = useToast();
|
||||
const [, { focusParamsTab, forceParamsRefresh, forceUrlRefresh }] = useRequestEditor();
|
||||
|
||||
return useMutation({
|
||||
return useFastMutation({
|
||||
mutationKey: ['import_querystring'],
|
||||
mutationFn: async (url: string) => {
|
||||
const split = url.split(/\?(.*)/s);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import { trackEvent } from '../lib/analytics';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
|
||||
export function useInstallPlugin() {
|
||||
return useMutation<void, unknown, string>({
|
||||
return useFastMutation<void, unknown, string>({
|
||||
mutationKey: ['install_plugin'],
|
||||
mutationFn: async (directory: string) => {
|
||||
await invokeCmd('cmd_install_plugin', { directory });
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import React from 'react';
|
||||
import { useDialog } from '../components/DialogContext';
|
||||
import { MoveToWorkspaceDialog } from '../components/MoveToWorkspaceDialog';
|
||||
@@ -11,7 +11,7 @@ export function useMoveToWorkspace(id: string) {
|
||||
const request = requests.find((r) => r.id === id);
|
||||
const activeWorkspace = useActiveWorkspace();
|
||||
|
||||
return useMutation<void, unknown>({
|
||||
return useFastMutation<void, unknown>({
|
||||
mutationKey: ['move_workspace', id],
|
||||
mutationFn: async () => {
|
||||
if (request == null || activeWorkspace == null) return;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import { SettingsTab } from '../components/Settings/Settings';
|
||||
import { trackEvent } from '../lib/analytics';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
@@ -9,7 +9,7 @@ import { useActiveWorkspace } from './useActiveWorkspace';
|
||||
export function useOpenSettings(tab = SettingsTab.General) {
|
||||
const workspace = useActiveWorkspace();
|
||||
|
||||
return useMutation({
|
||||
return useFastMutation({
|
||||
mutationKey: ['open_settings'],
|
||||
mutationFn: async () => {
|
||||
if (workspace == null) return;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { router } from '../main';
|
||||
import { Route as WorkspaceRoute } from '../routes/workspaces/$workspaceId';
|
||||
@@ -8,7 +8,7 @@ import { getRecentEnvironments } from './useRecentEnvironments';
|
||||
import { getRecentRequests } from './useRecentRequests';
|
||||
|
||||
export function useOpenWorkspace() {
|
||||
return useMutation({
|
||||
return useFastMutation({
|
||||
mutationKey: ['open_workspace'],
|
||||
mutationFn: async ({
|
||||
workspaceId,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import {useMutation} from "@tanstack/react-query";
|
||||
import type { Plugin } from '@yaakapp-internal/models';
|
||||
import { atom, useAtomValue, useSetAtom } from 'jotai';
|
||||
import { minPromiseMillis } from '../lib/minPromiseMillis';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { GrpcRequest, HttpRequest } from '@yaakapp-internal/models';
|
||||
import { InlineCode } from '../components/core/InlineCode';
|
||||
import { usePrompt } from './usePrompt';
|
||||
@@ -12,7 +12,8 @@ export function useRenameRequest(requestId: string | null) {
|
||||
const updateGrpcRequest = useUpdateAnyGrpcRequest();
|
||||
const requests = useRequests();
|
||||
|
||||
return useMutation({
|
||||
return useFastMutation({
|
||||
mutationKey: ['rename_request'],
|
||||
mutationFn: async () => {
|
||||
const request = requests.find((r) => r.id === requestId);
|
||||
if (request == null) return;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import { save } from '@tauri-apps/plugin-dialog';
|
||||
import mime from 'mime';
|
||||
import slugify from 'slugify';
|
||||
@@ -12,7 +12,7 @@ import { invokeCmd } from '../lib/tauri';
|
||||
export function useSaveResponse(response: HttpResponse) {
|
||||
const toast = useToast();
|
||||
|
||||
return useMutation({
|
||||
return useFastMutation({
|
||||
mutationKey: ['save_response', response.id],
|
||||
mutationFn: async () => {
|
||||
const request = await getHttpRequest(response.requestId);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { HttpResponse } from '@yaakapp-internal/models';
|
||||
import { trackEvent } from '../lib/analytics';
|
||||
import { getHttpRequest } from '../lib/store';
|
||||
@@ -11,7 +11,7 @@ export function useSendAnyHttpRequest() {
|
||||
const alert = useAlert();
|
||||
const [environment] = useActiveEnvironment();
|
||||
const [activeCookieJar] = useActiveCookieJar();
|
||||
return useMutation<HttpResponse | null, string, string | null>({
|
||||
return useFastMutation<HttpResponse | null, string, string | null>({
|
||||
mutationKey: ['send_any_request'],
|
||||
mutationFn: async (id) => {
|
||||
const request = await getHttpRequest(id);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import { useSendAnyHttpRequest } from './useSendAnyHttpRequest';
|
||||
|
||||
export function useSendManyRequests() {
|
||||
const sendAnyRequest = useSendAnyHttpRequest();
|
||||
return useMutation<void, string, string[]>({
|
||||
return useFastMutation<void, string, string[]>({
|
||||
mutationKey: ['send_many_requests'],
|
||||
mutationFn: async (requestIds: string[]) => {
|
||||
for (const id of requestIds) {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { Plugin } from '@yaakapp-internal/models';
|
||||
import { trackEvent } from '../lib/analytics';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
|
||||
export function useUninstallPlugin(pluginId: string) {
|
||||
return useMutation<Plugin | null, string>({
|
||||
return useFastMutation<Plugin | null, string>({
|
||||
mutationKey: ['uninstall_plugin'],
|
||||
mutationFn: async () => {
|
||||
return invokeCmd('cmd_uninstall_plugin', { pluginId });
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { Folder } from '@yaakapp-internal/models';
|
||||
import {useSetAtom} from "jotai/index";
|
||||
import { getFolder } from '../lib/store';
|
||||
@@ -8,7 +8,7 @@ import {updateModelList} from "./useSyncModelStores";
|
||||
|
||||
export function useUpdateAnyFolder() {
|
||||
const setFolders = useSetAtom(foldersAtom);
|
||||
return useMutation<Folder, unknown, { id: string; update: (r: Folder) => Folder }>({
|
||||
return useFastMutation<Folder, unknown, { id: string; update: (r: Folder) => Folder }>({
|
||||
mutationKey: ['update_any_folder'],
|
||||
mutationFn: async ({ id, update }) => {
|
||||
const folder = await getFolder(id);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { GrpcRequest } from '@yaakapp-internal/models';
|
||||
import { useSetAtom } from 'jotai/index';
|
||||
import { getGrpcRequest } from '../lib/store';
|
||||
@@ -8,7 +8,7 @@ import { updateModelList } from './useSyncModelStores';
|
||||
|
||||
export function useUpdateAnyGrpcRequest() {
|
||||
const setGrpcRequests = useSetAtom(grpcRequestsAtom);
|
||||
return useMutation<
|
||||
return useFastMutation<
|
||||
GrpcRequest,
|
||||
unknown,
|
||||
{ id: string; update: Partial<GrpcRequest> | ((r: GrpcRequest) => GrpcRequest) }
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { HttpRequest } from '@yaakapp-internal/models';
|
||||
import {useSetAtom} from "jotai/index";
|
||||
import { getHttpRequest } from '../lib/store';
|
||||
@@ -8,7 +8,7 @@ import {updateModelList} from "./useSyncModelStores";
|
||||
|
||||
export function useUpdateAnyHttpRequest() {
|
||||
const setHttpRequests = useSetAtom(httpRequestsAtom);
|
||||
return useMutation<
|
||||
return useFastMutation<
|
||||
HttpRequest,
|
||||
unknown,
|
||||
{ id: string; update: Partial<HttpRequest> | ((r: HttpRequest) => HttpRequest) }
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { CookieJar } from '@yaakapp-internal/models';
|
||||
import { useSetAtom } from 'jotai/index';
|
||||
import { getCookieJar } from '../lib/store';
|
||||
@@ -8,7 +8,7 @@ import { updateModelList } from './useSyncModelStores';
|
||||
|
||||
export function useUpdateCookieJar(id: string | null) {
|
||||
const setCookieJars = useSetAtom(cookieJarsAtom);
|
||||
return useMutation<CookieJar, unknown, Partial<CookieJar> | ((j: CookieJar) => CookieJar)>({
|
||||
return useFastMutation<CookieJar, unknown, Partial<CookieJar> | ((j: CookieJar) => CookieJar)>({
|
||||
mutationKey: ['update_cookie_jar', id],
|
||||
mutationFn: async (v) => {
|
||||
const cookieJar = await getCookieJar(id);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { Environment } from '@yaakapp-internal/models';
|
||||
import { useSetAtom } from 'jotai/index';
|
||||
import { getEnvironment } from '../lib/store';
|
||||
@@ -8,7 +8,7 @@ import {updateModelList} from "./useSyncModelStores";
|
||||
|
||||
export function useUpdateEnvironment(id: string | null) {
|
||||
const setEnvironments = useSetAtom(environmentsAtom);
|
||||
return useMutation<
|
||||
return useFastMutation<
|
||||
Environment,
|
||||
unknown,
|
||||
Partial<Environment> | ((r: Environment) => Environment)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { Settings } from '@yaakapp-internal/models';
|
||||
import { useSetAtom } from 'jotai';
|
||||
import { getSettings } from '../lib/store';
|
||||
@@ -7,7 +7,7 @@ import { settingsAtom } from './useSettings';
|
||||
|
||||
export function useUpdateSettings() {
|
||||
const setSettings = useSetAtom(settingsAtom);
|
||||
return useMutation<Settings, unknown, Partial<Settings>>({
|
||||
return useFastMutation<Settings, unknown, Partial<Settings>>({
|
||||
mutationKey: ['update_settings'],
|
||||
mutationFn: async (patch) => {
|
||||
const settings = await getSettings();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMutation } from './useMutation';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import type { Workspace } from '@yaakapp-internal/models';
|
||||
import {useSetAtom} from "jotai/index";
|
||||
import { getWorkspace } from '../lib/store';
|
||||
@@ -8,7 +8,7 @@ import {workspacesAtom} from "./useWorkspaces";
|
||||
|
||||
export function useUpdateWorkspace(id: string | null) {
|
||||
const setWorkspaces = useSetAtom(workspacesAtom);
|
||||
return useMutation<Workspace, unknown, Partial<Workspace> | ((w: Workspace) => Workspace)>({
|
||||
return useFastMutation<Workspace, unknown, Partial<Workspace> | ((w: Workspace) => Workspace)>({
|
||||
mutationKey: ['update_workspace', id],
|
||||
mutationFn: async (v) => {
|
||||
const workspace = await getWorkspace(id);
|
||||
|
||||
Reference in New Issue
Block a user