mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-28 12:11:53 +01:00
Fix workspace creation, reveal sync dir, and don't update timestamps on sync/import
This commit is contained in:
@@ -1,44 +0,0 @@
|
||||
import { router } from '../lib/router';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
import { getRecentCookieJars } from './useRecentCookieJars';
|
||||
import { getRecentEnvironments } from './useRecentEnvironments';
|
||||
import { getRecentRequests } from './useRecentRequests';
|
||||
|
||||
export function useSwitchWorkspace() {
|
||||
return useFastMutation({
|
||||
mutationKey: ['open_workspace'],
|
||||
mutationFn: async ({
|
||||
workspaceId,
|
||||
inNewWindow,
|
||||
}: {
|
||||
workspaceId: string;
|
||||
inNewWindow: boolean;
|
||||
}) => {
|
||||
const environmentId = (await getRecentEnvironments(workspaceId))[0] ?? undefined;
|
||||
const requestId = (await getRecentRequests(workspaceId))[0] ?? undefined;
|
||||
const cookieJarId = (await getRecentCookieJars(workspaceId))[0] ?? undefined;
|
||||
const search = {
|
||||
environment_id: environmentId,
|
||||
cookie_jar_id: cookieJarId,
|
||||
request_id: requestId,
|
||||
};
|
||||
|
||||
if (inNewWindow) {
|
||||
const location = router.buildLocation({
|
||||
to: '/workspaces/$workspaceId',
|
||||
params: { workspaceId },
|
||||
search,
|
||||
});
|
||||
await invokeCmd('cmd_new_main_window', { url: location.href });
|
||||
return;
|
||||
}
|
||||
|
||||
await router.navigate({
|
||||
to: '/workspaces/$workspaceId',
|
||||
params: { workspaceId },
|
||||
search,
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { WorkspaceMeta } from '@yaakapp-internal/models';
|
||||
import { useEffect } from 'react';
|
||||
import { jotaiStore } from '../lib/jotai';
|
||||
import { getWorkspaceMeta } from '../lib/store';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { activeWorkspaceIdAtom, getActiveWorkspaceId } from './useActiveWorkspace';
|
||||
import { cookieJarsAtom } from './useCookieJars';
|
||||
@@ -26,10 +26,9 @@ async function sync() {
|
||||
jotaiStore.set(keyValuesAtom, await invokeCmd('cmd_list_key_values'));
|
||||
|
||||
const workspaceId = getActiveWorkspaceId();
|
||||
if (workspaceId == null) return;
|
||||
|
||||
const args = { workspaceId };
|
||||
if (workspaceId == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Set the things we need first, first
|
||||
jotaiStore.set(httpRequestsAtom, await invokeCmd('cmd_list_http_requests', args));
|
||||
@@ -43,5 +42,5 @@ async function sync() {
|
||||
jotaiStore.set(environmentsAtom, await invokeCmd('cmd_list_environments', args));
|
||||
|
||||
// Single models
|
||||
jotaiStore.set(workspaceMetaAtom, await invokeCmd<WorkspaceMeta>('cmd_get_workspace_meta', args));
|
||||
jotaiStore.set(workspaceMetaAtom, await getWorkspaceMeta(workspaceId));
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
import type { Workspace } from '@yaakapp-internal/models';
|
||||
import { getWorkspace } from '../lib/store';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { useFastMutation } from './useFastMutation';
|
||||
|
||||
export function useUpdateWorkspace(id: string | null) {
|
||||
return useFastMutation<Workspace, unknown, Partial<Workspace> | ((w: Workspace) => Workspace)>({
|
||||
mutationKey: ['update_workspace', id],
|
||||
mutationFn: async (v) => {
|
||||
const workspace = await getWorkspace(id);
|
||||
if (workspace == null) {
|
||||
throw new Error("Can't update a null workspace");
|
||||
}
|
||||
|
||||
const newWorkspace = typeof v === 'function' ? v(workspace) : { ...workspace, ...v };
|
||||
return invokeCmd('cmd_update_workspace', { workspace: newWorkspace });
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -1,13 +1,8 @@
|
||||
import type { WorkspaceMeta } from '@yaakapp-internal/models';
|
||||
import { atom, useAtomValue } from 'jotai';
|
||||
|
||||
export const workspaceMetaAtom = atom<WorkspaceMeta>();
|
||||
export const workspaceMetaAtom = atom<WorkspaceMeta | null>(null);
|
||||
|
||||
export function useWorkspaceMeta() {
|
||||
const workspaceMeta = useAtomValue(workspaceMetaAtom);
|
||||
if (!workspaceMeta) {
|
||||
throw new Error('WorkspaceMeta not found');
|
||||
}
|
||||
|
||||
return workspaceMeta;
|
||||
return useAtomValue(workspaceMetaAtom);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user