mirror of
https://github.com/kmc7468/arkvault.git
synced 2026-02-04 08:06:56 +00:00
61 lines
2.0 KiB
Svelte
61 lines
2.0 KiB
Svelte
<script lang="ts">
|
|
import { BottomDiv, BottomSheet, Button, FullscreenDiv } from "$lib/components/atoms";
|
|
import { SubCategories } from "$lib/components/molecules";
|
|
import { CategoryCreateModal } from "$lib/components/organisms";
|
|
import { getCategoryInfo, type MaybeCategoryInfo } from "$lib/modules/filesystem";
|
|
import { masterKeyStore } from "$lib/stores";
|
|
import { requestCategoryCreation } from "./service";
|
|
|
|
interface Props {
|
|
onAddToCategoryClick: (categoryId: number) => void;
|
|
isOpen: boolean;
|
|
}
|
|
|
|
let { onAddToCategoryClick, isOpen = $bindable() }: Props = $props();
|
|
|
|
let categoryInfoPromise: Promise<MaybeCategoryInfo> | undefined = $state();
|
|
|
|
let isCategoryCreateModalOpen = $state(false);
|
|
|
|
$effect(() => {
|
|
if (isOpen) {
|
|
categoryInfoPromise = getCategoryInfo("root", $masterKeyStore?.get(1)?.key!);
|
|
}
|
|
});
|
|
</script>
|
|
|
|
{#await categoryInfoPromise then categoryInfo}
|
|
{#if categoryInfo?.exists}
|
|
<BottomSheet bind:isOpen class="flex flex-col">
|
|
<FullscreenDiv>
|
|
<SubCategories
|
|
class="py-4"
|
|
info={categoryInfo}
|
|
onSubCategoryClick={({ id }) =>
|
|
(categoryInfoPromise = getCategoryInfo(id, $masterKeyStore?.get(1)?.key!))}
|
|
onSubCategoryCreateClick={() => (isCategoryCreateModalOpen = true)}
|
|
subCategoryCreatePosition="top"
|
|
/>
|
|
{#if categoryInfo.id !== "root"}
|
|
<BottomDiv>
|
|
<Button onclick={() => onAddToCategoryClick(categoryInfo.id)} class="w-full">
|
|
이 카테고리에 추가하기
|
|
</Button>
|
|
</BottomDiv>
|
|
{/if}
|
|
</FullscreenDiv>
|
|
</BottomSheet>
|
|
|
|
<CategoryCreateModal
|
|
bind:isOpen={isCategoryCreateModalOpen}
|
|
onCreateClick={async (name: string) => {
|
|
if (await requestCategoryCreation(name, categoryInfo.id, $masterKeyStore?.get(1)!)) {
|
|
categoryInfoPromise = getCategoryInfo(categoryInfo.id, $masterKeyStore?.get(1)?.key!); // TODO: FIXME
|
|
return true;
|
|
}
|
|
return false;
|
|
}}
|
|
/>
|
|
{/if}
|
|
{/await}
|