Handle updating catalog

This commit is contained in:
ZXY101
2023-09-04 09:52:22 +02:00
parent 0627d1e547
commit 83b427f976
2 changed files with 17 additions and 2 deletions

View File

@@ -114,7 +114,21 @@ export async function processFiles(fileList: FileList) {
if (!valid.includes(false)) {
await requestPersistentStorage();
await db.catalog.put({ id: vols[0].mokuroData.title_uuid, manga: vols })
const key = vols[0].mokuroData.title_uuid;
const existingCatalog = await db.catalog.get(key);
if (existingCatalog) {
const filtered = vols.filter((vol) => {
return !existingCatalog.manga.some(manga => {
return manga.mokuroData.volume_uuid === vol.mokuroData.volume_uuid
})
})
await db.catalog.update(key, { manga: [...existingCatalog.manga, ...filtered] })
} else {
await db.catalog.put({ id: key, manga: vols })
}
showSnackbar('Catalog updated successfully')
}
}

View File

@@ -16,5 +16,6 @@
{#await promise}
<h2>Loading...</h2>
{:then}
<Catalog />
{/await}
<Catalog />