mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-18 14:59:42 +02:00
Start on plugin ctx API (#64)
This commit is contained in:
@@ -1,21 +1,21 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import type { Folder } from '@yaakapp/api';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { useActiveWorkspaceId } from './useActiveWorkspaceId';
|
||||
import { useActiveWorkspace } from './useActiveWorkspace';
|
||||
|
||||
export function foldersQueryKey({ workspaceId }: { workspaceId: string }) {
|
||||
return ['folders', { workspaceId }];
|
||||
}
|
||||
|
||||
export function useFolders() {
|
||||
const workspaceId = useActiveWorkspaceId();
|
||||
const workspace = useActiveWorkspace();
|
||||
return (
|
||||
useQuery({
|
||||
enabled: workspaceId != null,
|
||||
queryKey: foldersQueryKey({ workspaceId: workspaceId ?? 'n/a' }),
|
||||
enabled: workspace != null,
|
||||
queryKey: foldersQueryKey({ workspaceId: workspace?.id ?? 'n/a' }),
|
||||
queryFn: async () => {
|
||||
if (workspaceId == null) return [];
|
||||
return (await invokeCmd('cmd_list_folders', { workspaceId })) as Folder[];
|
||||
if (workspace == null) return [];
|
||||
return (await invokeCmd('cmd_list_folders', { workspaceId: workspace.id })) as Folder[];
|
||||
},
|
||||
}).data ?? []
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user