mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-20 15:51:23 +02:00
Fix performance related to having 100s of requests (#123)
This commit is contained in:
@@ -1,22 +1,9 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import type { Folder } from '@yaakapp-internal/models';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { useActiveWorkspace } from './useActiveWorkspace';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { atom } from 'jotai/index';
|
||||
|
||||
export function foldersQueryKey({ workspaceId }: { workspaceId: string }) {
|
||||
return ['folders', { workspaceId }];
|
||||
}
|
||||
export const foldersAtom = atom<Folder[]>([]);
|
||||
|
||||
export function useFolders() {
|
||||
const workspace = useActiveWorkspace();
|
||||
return (
|
||||
useQuery({
|
||||
enabled: workspace != null,
|
||||
queryKey: foldersQueryKey({ workspaceId: workspace?.id ?? 'n/a' }),
|
||||
queryFn: async () => {
|
||||
if (workspace == null) return [];
|
||||
return (await invokeCmd('cmd_list_folders', { workspaceId: workspace.id })) as Folder[];
|
||||
},
|
||||
}).data ?? []
|
||||
);
|
||||
return useAtomValue(foldersAtom);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user