mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-31 06:23:08 +02:00
Template Tag Function Editor (#67)

This commit is contained in:
26
src-web/hooks/useRenderTemplate.ts
Normal file
26
src-web/hooks/useRenderTemplate.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
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 });
|
||||
}
|
||||
Reference in New Issue
Block a user