mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-15 16:23:25 +01:00

27 lines
890 B
TypeScript
27 lines
890 B
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
import { invokeCmd } from '../lib/tauri';
|
|
import { useActiveEnvironment } from './useActiveEnvironment';
|
|
import { useActiveWorkspace } from './useActiveWorkspace';
|
|
|
|
export function useRenderTemplate(template: string) {
|
|
const workspaceId = useActiveWorkspace()?.id ?? 'n/a';
|
|
const environmentId = useActiveEnvironment()[0]?.id ?? null;
|
|
return useQuery<string>({
|
|
placeholderData: (prev) => prev, // Keep previous data on refetch
|
|
queryKey: ['render_template', template],
|
|
queryFn: () => renderTemplate({ template, workspaceId, environmentId }),
|
|
});
|
|
}
|
|
|
|
export async function renderTemplate({
|
|
template,
|
|
workspaceId,
|
|
environmentId,
|
|
}: {
|
|
template: string;
|
|
workspaceId: string;
|
|
environmentId: string | null;
|
|
}): Promise<string> {
|
|
return invokeCmd('cmd_render_template', { template, workspaceId, environmentId });
|
|
}
|