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