32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
|
|
import { useQuery } from '@tanstack/react-query';
|
||
|
|
import { api } from '../client';
|
||
|
|
|
||
|
|
export function useDiagramLayout(contentHash: string | null) {
|
||
|
|
return useQuery({
|
||
|
|
queryKey: ['diagrams', 'layout', contentHash],
|
||
|
|
queryFn: async () => {
|
||
|
|
const { data, error } = await api.GET('/diagrams/{contentHash}/render', {
|
||
|
|
params: { path: { contentHash: contentHash! } },
|
||
|
|
headers: { Accept: 'application/json' },
|
||
|
|
});
|
||
|
|
if (error) throw new Error('Failed to load diagram layout');
|
||
|
|
return data!;
|
||
|
|
},
|
||
|
|
enabled: !!contentHash,
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
export function useDiagramByRoute(group: string | undefined, routeId: string | undefined) {
|
||
|
|
return useQuery({
|
||
|
|
queryKey: ['diagrams', 'byRoute', group, routeId],
|
||
|
|
queryFn: async () => {
|
||
|
|
const { data, error } = await api.GET('/diagrams', {
|
||
|
|
params: { query: { group: group!, routeId: routeId! } },
|
||
|
|
});
|
||
|
|
if (error) throw new Error('Failed to load diagram for route');
|
||
|
|
return data!;
|
||
|
|
},
|
||
|
|
enabled: !!group && !!routeId,
|
||
|
|
});
|
||
|
|
}
|