Got key values working

This commit is contained in:
Gregory Schier
2023-03-15 23:24:41 -07:00
parent 83dbf46ba4
commit 41fc3afdc1
12 changed files with 553 additions and 298 deletions

View File

@@ -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");
}

View 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),
};
}

View File

@@ -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() {

View File

@@ -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() {