Generalized frontend model store (#193)

This commit is contained in:
Gregory Schier
2025-03-31 11:56:17 -07:00
committed by GitHub
parent ce885c3551
commit f1757ae427
201 changed files with 2185 additions and 2865 deletions

View File

@@ -1,17 +1,19 @@
import type { CookieJar } from '@yaakapp-internal/models';
import { createWorkspaceModel } from '@yaakapp-internal/models';
import { jotaiStore } from '../lib/jotai';
import { showPrompt } from '../lib/prompt';
import { invokeCmd } from '../lib/tauri';
import { getActiveWorkspaceId } from './useActiveWorkspace';
import { setWorkspaceSearchParams } from '../lib/setWorkspaceSearchParams';
import { activeWorkspaceIdAtom } from './useActiveWorkspace';
import { useFastMutation } from './useFastMutation';
export function useCreateCookieJar() {
return useFastMutation<CookieJar | null>({
return useFastMutation({
mutationKey: ['create_cookie_jar'],
mutationFn: async () => {
const workspaceId = getActiveWorkspaceId();
const workspaceId = jotaiStore.get(activeWorkspaceIdAtom);
if (workspaceId == null) {
throw new Error("Cannot create cookie jar when there's no active workspace");
}
const name = await showPrompt({
id: 'new-cookie-jar',
title: 'New CookieJar',
@@ -22,7 +24,10 @@ export function useCreateCookieJar() {
});
if (name == null) return null;
return invokeCmd('cmd_create_cookie_jar', { workspaceId, name });
return createWorkspaceModel({ model: 'cookie_jar', workspaceId, name });
},
onSuccess: async (cookieJarId) => {
setWorkspaceSearchParams({ cookie_jar_id: cookieJarId });
},
});
}