Add single volume deletion

This commit is contained in:
ZXY101
2024-02-28 00:15:36 +02:00
parent 1df387526a
commit 1946b12623
2 changed files with 50 additions and 33 deletions

View File

@@ -1,40 +1,72 @@
<script lang="ts"> <script lang="ts">
import { page } from '$app/stores'; import { page } from '$app/stores';
import { progress } from '$lib/settings'; import { deleteVolume, progress } from '$lib/settings';
import type { Volume } from '$lib/types'; import type { Volume } from '$lib/types';
import { ListgroupItem } from 'flowbite-svelte'; import { promptConfirmation } from '$lib/util';
import { CheckCircleSolid } from 'flowbite-svelte-icons'; import { ListgroupItem, Frame } from 'flowbite-svelte';
import type { ListGroupItemType } from 'flowbite-svelte/dist/types'; import { CheckCircleSolid, TrashBinSolid } from 'flowbite-svelte-icons';
import { goto } from '$app/navigation';
import { db } from '$lib/catalog/db';
export let item: string | ListGroupItemType; export let volume: Volume;
const volume = item as Volume;
const { volumeName, mokuroData } = volume as Volume; const { volumeName, mokuroData } = volume as Volume;
const { title_uuid, volume_uuid } = mokuroData;
const volName = decodeURI(volumeName);
$: currentPage = $progress?.[volume?.mokuroData.volume_uuid || 0] || 1; $: currentPage = $progress?.[volume_uuid || 0] || 1;
$: progressDisplay = `${ $: progressDisplay = `${
currentPage === volume.mokuroData.pages.length - 1 ? currentPage + 1 : currentPage currentPage === volume.mokuroData.pages.length - 1 ? currentPage + 1 : currentPage
} / ${volume.mokuroData.pages.length}`; } / ${volume.mokuroData.pages.length}`;
$: isComplete = $: isComplete =
currentPage === volume.mokuroData.pages.length || currentPage === volume.mokuroData.pages.length ||
currentPage === volume.mokuroData.pages.length - 1; currentPage === volume.mokuroData.pages.length - 1;
async function onDeleteClicked(e: Event) {
e.stopPropagation();
promptConfirmation(`Delete ${volName}?`, async () => {
const existingCatalog = await db.catalog.get(title_uuid);
const updated = existingCatalog?.manga.filter(({ mokuroData }) => {
return mokuroData.volume_uuid !== volume_uuid;
});
deleteVolume(volume_uuid);
if (updated && updated.length > 0) {
await db.catalog.update(title_uuid, { manga: updated });
goto(`/${$page.params.manga}`);
} else {
db.catalog.delete(title_uuid);
goto('/');
}
});
}
</script> </script>
{#if $page.params.manga} {#if $page.params.manga}
<a href={`/${$page.params.manga}/${mokuroData.volume_uuid}`} class="h-full w-full"> <Frame rounded border class="divide-y divide-gray-200 dark:divide-gray-600">
<ListgroupItem> <ListgroupItem
on:click={() => goto(`/${$page.params.manga}/${volume_uuid}`)}
normalClass="py-4"
>
<div <div
class:text-green-400={isComplete} class:text-green-400={isComplete}
class="flex flex-row gap-5 items-center justify-between w-full" class="flex flex-row gap-5 items-center justify-between w-full"
> >
<div> <div>
<p class="font-semibold" class:text-white={!isComplete}>{decodeURI(volumeName)}</p> <p class="font-semibold" class:text-white={!isComplete}>{volName}</p>
<p>{progressDisplay}</p> <p>{progressDisplay}</p>
</div> </div>
<div class="flex gap-2">
<TrashBinSolid
class="text-red-400 hover:text-red-500 z-10 poin"
on:click={onDeleteClicked}
/>
{#if isComplete} {#if isComplete}
<CheckCircleSolid /> <CheckCircleSolid />
{/if} {/if}
</div> </div>
</div>
</ListgroupItem> </ListgroupItem>
</a> </Frame>
{/if} {/if}

View File

@@ -21,23 +21,6 @@
$: manga = $catalog?.find((item) => item.id === $page.params.manga)?.manga.sort(sortManga); $: manga = $catalog?.find((item) => item.id === $page.params.manga)?.manga.sort(sortManga);
$: stats = manga
?.map((vol) => vol.mokuroData.volume_uuid)
?.reduce(
(stats: any, volumeId) => {
const timeReadInMinutes = $volumes[volumeId]?.timeReadInMinutes || 0;
const chars = $volumes[volumeId]?.chars || 0;
const completed = $volumes[volumeId]?.completed || 0;
stats.timeReadInMinutes = stats.timeReadInMinutes + timeReadInMinutes;
stats.chars = stats.chars + chars;
stats.completed = stats.completed + completed;
return stats;
},
{ timeReadInMinutes: 0, chars: 0, completed: 0 }
);
$: loading = false; $: loading = false;
async function confirmDelete() { async function confirmDelete() {
@@ -84,8 +67,10 @@
</Button> </Button>
</div> </div>
</div> </div>
<Listgroup items={manga} let:item active class="flex-1 h-full w-full"> <Listgroup active class="flex-1 h-full w-full">
<VolumeItem {item} /> {#each manga as volume (volume.mokuroData.volume_uuid)}
<VolumeItem {volume} />
{/each}
</Listgroup> </Listgroup>
</div> </div>
{:else} {:else}