mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-24 18:31:16 +01:00
Got key values working
This commit is contained in:
@@ -8,7 +8,7 @@ export function useCreateRequest({ navigateAfter }: { navigateAfter: boolean })
|
||||
const workspace = useActiveWorkspace();
|
||||
const navigate = useNavigate();
|
||||
return useMutation<string, unknown, Pick<HttpRequest, 'name'>>({
|
||||
mutationFn: async (patch) => {
|
||||
mutationFn: (patch) => {
|
||||
if (workspace === null) {
|
||||
throw new Error("Cannot create request when there's no active workspace");
|
||||
}
|
||||
|
||||
26
src-web/hooks/useKeyValues.ts
Normal file
26
src-web/hooks/useKeyValues.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { useMutation, useQuery } from '@tanstack/react-query';
|
||||
import { invoke } from '@tauri-apps/api';
|
||||
import type { KeyValue } from '../lib/models';
|
||||
|
||||
export function keyValueQueryKey(namespace: string, key: string) {
|
||||
return ['key_value', { namespace, key }];
|
||||
}
|
||||
|
||||
export function useKeyValues(namespace: string, key: string) {
|
||||
const query = useQuery<KeyValue | null>({
|
||||
initialData: null,
|
||||
queryKey: keyValueQueryKey(namespace, key),
|
||||
queryFn: async () => invoke('get_key_value', { namespace, key }),
|
||||
});
|
||||
|
||||
const mutate = useMutation<KeyValue, unknown, KeyValue['value']>({
|
||||
mutationFn: (value) => {
|
||||
return invoke('set_key_value', { namespace, key, value });
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
value: query.data?.value ?? null,
|
||||
set: (value: KeyValue['value']) => mutate.mutate(value),
|
||||
};
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import { convertDates } from '../lib/models';
|
||||
import { useActiveWorkspace } from './useActiveWorkspace';
|
||||
|
||||
export function requestsQueryKey(workspaceId: string) {
|
||||
return ['requests', { workspaceId }];
|
||||
return ['http_requests', { workspaceId }];
|
||||
}
|
||||
|
||||
export function useRequests() {
|
||||
|
||||
@@ -5,7 +5,7 @@ import { convertDates } from '../lib/models';
|
||||
import { useActiveRequest } from './useActiveRequest';
|
||||
|
||||
export function responsesQueryKey(requestId: string) {
|
||||
return ['responses', { requestId }];
|
||||
return ['http_responses', { requestId }];
|
||||
}
|
||||
|
||||
export function useResponses() {
|
||||
|
||||
Reference in New Issue
Block a user