mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-24 01:38:26 +02:00
Fix performance related to having 100s of requests (#123)
This commit is contained in:
@@ -1,22 +1,8 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import type { CookieJar } from '@yaakapp-internal/models';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { useActiveWorkspace } from './useActiveWorkspace';
|
||||
import { atom, useAtomValue } from 'jotai';
|
||||
|
||||
export function cookieJarsQueryKey({ workspaceId }: { workspaceId: string }) {
|
||||
return ['cookie_jars', { workspaceId }];
|
||||
}
|
||||
export const cookieJarsAtom = atom<CookieJar[]>([]);
|
||||
|
||||
export function useCookieJars() {
|
||||
const workspace = useActiveWorkspace();
|
||||
return useQuery({
|
||||
enabled: workspace != null,
|
||||
queryKey: cookieJarsQueryKey({ workspaceId: workspace?.id ?? 'n/a' }),
|
||||
queryFn: async () => {
|
||||
if (workspace == null) return [];
|
||||
return (await invokeCmd('cmd_list_cookie_jars', {
|
||||
workspaceId: workspace.id,
|
||||
})) as CookieJar[];
|
||||
},
|
||||
});
|
||||
return useAtomValue(cookieJarsAtom);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user