기존에 제작된 모달들을 ActionModal 컴포넌트 기반으로 재구성

This commit is contained in:
static
2025-01-25 22:30:06 +09:00
parent 38a1c8d7e0
commit 7dba1cf4c6
26 changed files with 367 additions and 387 deletions

View File

@@ -0,0 +1,34 @@
import { getContext, setContext } from "svelte";
import { callPostApi } from "$lib/hooks";
import { encryptString } from "$lib/modules/crypto";
import type { SelectedCategory } from "$lib/molecules/Categories";
import type { CategoryRenameRequest } from "$lib/server/schemas";
export { requestCategoryCreation, requestFileRemovalFromCategory } from "$lib/services/category";
export const createContext = () => {
const context = $state({
selectedCategory: undefined as SelectedCategory | undefined,
});
return setContext("context", context);
};
export const useContext = () => {
return getContext<ReturnType<typeof createContext>>("context");
};
export const requestCategoryRename = async (category: SelectedCategory, newName: string) => {
const newNameEncrypted = await encryptString(newName, category.dataKey);
const res = await callPostApi<CategoryRenameRequest>(`/api/category/${category.id}/rename`, {
dekVersion: category.dataKeyVersion.toISOString(),
name: newNameEncrypted.ciphertext,
nameIv: newNameEncrypted.iv,
});
return res.ok;
};
export const requestCategoryDeletion = async (category: SelectedCategory) => {
const res = await callPostApi(`/api/category/${category.id}/delete`);
return res.ok;
};