From 1979cd2ea4bcee087dde97ce3acdcb3fd3b582a2 Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Thu, 5 Sep 2024 09:38:29 +0500 Subject: [PATCH] web: show progress when rechecking attachments in bulk --- apps/web/src/stores/attachment-store.ts | 48 +++++++++++++++---------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/apps/web/src/stores/attachment-store.ts b/apps/web/src/stores/attachment-store.ts index 3eb40947f..06e30075e 100644 --- a/apps/web/src/stores/attachment-store.ts +++ b/apps/web/src/stores/attachment-store.ts @@ -28,6 +28,7 @@ import { AttachmentStream } from "../utils/streams/attachment-stream"; import { createZipStream } from "../utils/streams/zip-stream"; import { createWriteStream } from "../utils/stream-saver"; import { Attachment } from "@notesnook/core"; +import { TaskManager } from "../common/task-manager"; let abortController: AbortController | undefined = undefined; class AttachmentStore extends BaseStore { @@ -80,25 +81,36 @@ class AttachmentStore extends BaseStore { }; recheck = async (ids: string[]) => { - for (const id of ids) { - const attachment = await db.attachments.attachment(id); - if (!attachment) continue; - try { - this._changeWorkingStatus(attachment.hash, "recheck"); + await TaskManager.startTask({ + type: "status", + action: async (report) => { + let i = 0; + for (const id of ids) { + report({ + text: `Checking attachments (${++i}/${ids.length})` + }); + const attachment = await db.attachments.attachment(id); + if (!attachment) continue; + try { + this._changeWorkingStatus(attachment.hash, "recheck"); - const { failed, success } = await checkAttachment(attachment.hash); - this._changeWorkingStatus( - attachment.hash, - undefined, - success ? undefined : failed - ); - } catch (e) { - console.error(e); - this._changeWorkingStatus(attachment.hash); - if (e instanceof Error) - showToast("error", `Rechecking failed: ${e.message}`); - } - } + const { failed, success } = await checkAttachment(attachment.hash); + this._changeWorkingStatus( + attachment.hash, + undefined, + success ? undefined : failed + ); + } catch (e) { + console.error(e); + this._changeWorkingStatus(attachment.hash); + if (e instanceof Error) + showToast("error", `Rechecking failed: ${e.message}`); + } + } + }, + id: "checking-attachments", + title: "Checking attachments" + }); }; rename = async (hash: string, newName: string) => {