mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-16 14:06:49 +01:00
22 lines
777 B
TypeScript
22 lines
777 B
TypeScript
import { useFastMutation } from './useFastMutation';
|
|
import type { Settings } from '@yaakapp-internal/models';
|
|
import { useSetAtom } from 'jotai';
|
|
import { getSettings } from '../lib/store';
|
|
import { invokeCmd } from '../lib/tauri';
|
|
import { settingsAtom } from './useSettings';
|
|
|
|
export function useUpdateSettings() {
|
|
const setSettings = useSetAtom(settingsAtom);
|
|
return useFastMutation<Settings, unknown, Partial<Settings>>({
|
|
mutationKey: ['update_settings'],
|
|
mutationFn: async (patch) => {
|
|
const settings = await getSettings();
|
|
const newSettings: Settings = { ...settings, ...patch };
|
|
return invokeCmd<Settings>('cmd_update_settings', { settings: newSettings });
|
|
},
|
|
onSuccess: (settings) => {
|
|
setSettings(settings);
|
|
},
|
|
});
|
|
}
|