mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-18 06:57:11 +01:00
20 lines
739 B
TypeScript
20 lines
739 B
TypeScript
import { useMutation } from '@tanstack/react-query';
|
|
import type { CookieJar } from '@yaakapp/api';
|
|
import { getCookieJar } from '../lib/store';
|
|
import { invokeCmd } from '../lib/tauri';
|
|
|
|
export function useUpdateCookieJar(id: string | null) {
|
|
return useMutation<void, unknown, Partial<CookieJar> | ((j: CookieJar) => CookieJar)>({
|
|
mutationKey: ['update_cookie_jar', id],
|
|
mutationFn: async (v) => {
|
|
const cookieJar = await getCookieJar(id);
|
|
if (cookieJar == null) {
|
|
throw new Error("Can't update a null workspace");
|
|
}
|
|
|
|
const newCookieJar = typeof v === 'function' ? v(cookieJar) : { ...cookieJar, ...v };
|
|
await invokeCmd('cmd_update_cookie_jar', { cookieJar: newCookieJar });
|
|
},
|
|
});
|
|
}
|