mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-02-25 09:04:57 +01:00
25 lines
777 B
TypeScript
25 lines
777 B
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
import type { Environment } from '@yaakapp/api';
|
|
import { invokeCmd } from '../lib/tauri';
|
|
import { useActiveWorkspace } from './useActiveWorkspace';
|
|
|
|
export function environmentsQueryKey({ workspaceId }: { workspaceId: string }) {
|
|
return ['environments', { workspaceId }];
|
|
}
|
|
|
|
export function useEnvironments() {
|
|
const workspace = useActiveWorkspace();
|
|
return (
|
|
useQuery({
|
|
enabled: workspace != null,
|
|
queryKey: environmentsQueryKey({ workspaceId: workspace?.id ?? 'n/a' }),
|
|
queryFn: async () => {
|
|
if (workspace == null) return [];
|
|
return (await invokeCmd('cmd_list_environments', {
|
|
workspaceId: workspace.id,
|
|
})) as Environment[];
|
|
},
|
|
}).data ?? []
|
|
);
|
|
}
|