Initial settings implementation

This commit is contained in:
Gregory Schier
2024-01-11 21:13:17 -08:00
parent 11161fda51
commit 202e272e90
18 changed files with 426 additions and 65 deletions

View File

@@ -11,7 +11,8 @@ export type HotkeyAction =
| 'sidebar.focus'
| 'urlBar.focus'
| 'environmentEditor.toggle'
| 'hotkeys.showHelp';
| 'hotkeys.showHelp'
| 'settings.show';
const hotkeys: Record<HotkeyAction, string[]> = {
'request.send': ['CmdCtrl+Enter', 'CmdCtrl+r'],
@@ -22,6 +23,7 @@ const hotkeys: Record<HotkeyAction, string[]> = {
'urlBar.focus': ['CmdCtrl+l'],
'environmentEditor.toggle': ['CmdCtrl+e'],
'hotkeys.showHelp': ['CmdCtrl+/'],
'settings.show': ['CmdCtrl+,'],
};
const hotkeyLabels: Record<HotkeyAction, string> = {
@@ -32,7 +34,8 @@ const hotkeyLabels: Record<HotkeyAction, string> = {
'sidebar.focus': 'Focus Sidebar',
'urlBar.focus': 'Focus URL',
'environmentEditor.toggle': 'Edit Environments',
'hotkeys.showHelp': 'Show Hotkeys',
'hotkeys.showHelp': 'Show Keyboard Shortcuts',
'settings.show': 'Open Settings',
};
export const hotkeyActions: HotkeyAction[] = Object.keys(hotkeys) as (keyof typeof hotkeys)[];

View File

@@ -0,0 +1,18 @@
import { useQuery } from '@tanstack/react-query';
import { invoke } from '@tauri-apps/api';
import type { Settings } from '../lib/models';
export function settingsQueryKey() {
return ['settings'];
}
export function useSettings() {
return (
useQuery({
queryKey: settingsQueryKey(),
queryFn: async () => {
return (await invoke('get_settings')) as Settings;
},
}).data ?? undefined
);
}

View File

@@ -0,0 +1,18 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { invoke } from '@tauri-apps/api';
import type { HttpRequest, Settings } from '../lib/models';
import { requestsQueryKey } from './useRequests';
import { settingsQueryKey } from './useSettings';
export function useUpdateSettings() {
const queryClient = useQueryClient();
return useMutation<void, unknown, Settings>({
mutationFn: async (settings) => {
await invoke('update_settings', { settings });
},
onMutate: async (settings) => {
queryClient.setQueryData<Settings>(settingsQueryKey(), settings);
},
});
}