mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-21 08:59:07 +01:00
JSONPath filter plugins working
This commit is contained in:
23
src-web/hooks/useFilterResponse.ts
Normal file
23
src-web/hooks/useFilterResponse.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { invoke } from '@tauri-apps/api';
|
||||
|
||||
export function useFilterResponse({
|
||||
responseId,
|
||||
filter,
|
||||
}: {
|
||||
responseId: string | null;
|
||||
filter: string;
|
||||
}) {
|
||||
return (
|
||||
useQuery<string | null>({
|
||||
queryKey: [responseId, filter],
|
||||
queryFn: async () => {
|
||||
if (filter === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (await invoke('filter_response', { responseId, filter })) as string | null;
|
||||
},
|
||||
}).data ?? null
|
||||
);
|
||||
}
|
||||
7
src-web/hooks/useToggle.ts
Normal file
7
src-web/hooks/useToggle.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { useCallback, useState } from 'react';
|
||||
|
||||
export function useToggle(initialValue = false) {
|
||||
const [value, setValue] = useState<boolean>(initialValue);
|
||||
const toggle = useCallback(() => setValue((v) => !v), []);
|
||||
return [value, toggle] as const;
|
||||
}
|
||||
Reference in New Issue
Block a user