mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-25 02:41:07 +01:00
Start on plugin ctx API (#64)
This commit is contained in:
@@ -1,12 +1,9 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { useMutation } from '@tanstack/react-query';
|
||||
import type { Folder } from '@yaakapp/api';
|
||||
import { getFolder } from '../lib/store';
|
||||
import { invokeCmd } from '../lib/tauri';
|
||||
import { foldersQueryKey } from './useFolders';
|
||||
|
||||
export function useUpdateAnyFolder() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation<void, unknown, { id: string; update: (r: Folder) => Folder }>({
|
||||
mutationKey: ['update_any_folder'],
|
||||
mutationFn: async ({ id, update }) => {
|
||||
@@ -17,12 +14,5 @@ export function useUpdateAnyFolder() {
|
||||
|
||||
await invokeCmd('cmd_update_folder', { folder: update(folder) });
|
||||
},
|
||||
onMutate: async ({ id, update }) => {
|
||||
const folder = await getFolder(id);
|
||||
if (folder === null) return;
|
||||
queryClient.setQueryData<Folder[]>(foldersQueryKey(folder), (folders) =>
|
||||
(folders ?? []).map((f) => (f.id === folder.id ? update(f) : f)),
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user