mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-30 20:54:14 +02:00
Performance sweep (#147)
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useMutation } from './useMutation';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { useAppRoutes } from './useAppRoutes';
|
||||
import { router } from '../main';
|
||||
import { Route as WorkspaceRoute } from '../routes/workspaces/$workspaceId';
|
||||
import { Route as RequestRoute } from '../routes/workspaces/$workspaceId/requests/$requestId';
|
||||
import { getRecentCookieJars } from './useRecentCookieJars';
|
||||
import { getRecentEnvironments } from './useRecentEnvironments';
|
||||
import { getRecentRequests } from './useRecentRequests';
|
||||
|
||||
export function useOpenWorkspace() {
|
||||
const routes = useAppRoutes();
|
||||
|
||||
return useMutation({
|
||||
mutationKey: ['open_workspace'],
|
||||
mutationFn: async ({
|
||||
@@ -17,22 +17,25 @@ export function useOpenWorkspace() {
|
||||
workspaceId: string;
|
||||
inNewWindow: boolean;
|
||||
}) => {
|
||||
const environmentId = (await getRecentEnvironments(workspaceId))[0] ?? null;
|
||||
const requestId = (await getRecentRequests(workspaceId))[0] ?? null;
|
||||
const cookieJarId = (await getRecentCookieJars(workspaceId))[0] ?? null;
|
||||
const baseArgs = { workspaceId, environmentId, cookieJarId } as const;
|
||||
const environmentId = (await getRecentEnvironments(workspaceId))[0] ?? undefined;
|
||||
const requestId = (await getRecentRequests(workspaceId))[0] ?? undefined;
|
||||
const cookieJarId = (await getRecentCookieJars(workspaceId))[0] ?? undefined;
|
||||
const search = { environmentId, cookieJarId };
|
||||
|
||||
if (inNewWindow) {
|
||||
const path =
|
||||
requestId != null
|
||||
? routes.paths.request({ ...baseArgs, requestId })
|
||||
: routes.paths.workspace({ ...baseArgs });
|
||||
await invokeCmd('cmd_new_main_window', { url: path });
|
||||
const location = router.buildLocation({
|
||||
to: WorkspaceRoute.fullPath,
|
||||
params: { workspaceId },
|
||||
search,
|
||||
});
|
||||
await invokeCmd('cmd_new_main_window', { url: location });
|
||||
return;
|
||||
}
|
||||
|
||||
if (requestId != null) {
|
||||
router.navigate({ to: RequestRoute.fullPath, params: { workspaceId, requestId }, search });
|
||||
} else {
|
||||
if (requestId != null) {
|
||||
routes.navigate('request', { ...baseArgs, requestId });
|
||||
} else {
|
||||
routes.navigate('workspace', { ...baseArgs });
|
||||
}
|
||||
router.navigate({ to: WorkspaceRoute.fullPath, params: { workspaceId }, search });
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user