Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

refactor: use taskmanager instead of progress dialog

thecodrrdc56b6844d00
diff --git a/apps/web/src/components/editor/plugins/picker.js b/apps/web/src/components/editor/plugins/picker.js
index ff9a422fc..e061a9583 100644
--- a/apps/web/src/components/editor/plugins/picker.js
+++ b/apps/web/src/components/editor/plugins/picker.js
@@ -1,10 +1,8 @@
import Compressor from "compressorjs";
import { AppEventManager, AppEvents } from "../../../common/app-events";
import { db } from "../../../common/db";
-import {
- showBuyDialog,
- showProgressDialog,
-} from "../../../common/dialog-controller";
+import { showBuyDialog } from "../../../common/dialog-controller";
+import { TaskManager } from "../../../common/task-manager";
import { isUserPremium } from "../../../hooks/use-is-user-premium";
import fs from "../../../interfaces/fs";
import { formatBytes } from "../../../utils/filename";
@@ -158,26 +156,23 @@ function compressImage(file) {
* @returns
*/
async function addAttachment(file, dataurl) {
- const result = await showProgressDialog({
- title: `Encrypting attachment`,
+ const result = await TaskManager.startTask({
+ type: "modal",
+ title: "Encrypting attachment",
subtitle: "Please wait while we encrypt this attachment for upload.",
- message: file.name,
- total: formatBytes(file.size, 0),
- setProgress: (set) => {
+ action: async (report) => {
const event = AppEventManager.subscribe(
AppEvents.UPDATE_ATTACHMENT_PROGRESS,
({ type, total, loaded }) => {
if (type !== "encrypt") return;
-
- const percent = Math.round((loaded / total) * 100);
- set({ loaded: formatBytes(loaded, 0), progress: percent });
+ report({
+ current: formatBytes(loaded, 0),
+ total: total,
+ text: file.name,
+ });
}
);
- return () => {
- event.unsubscribe();
- };
- },
- action: async () => {
+
const key = await getEncryptionKey();
const reader = file.stream().getReader();
@@ -198,6 +193,7 @@ async function addAttachment(file, dataurl) {
});
}
+ event.unsubscribe();
return {
hash: hash,
filename: file.name,
@@ -207,7 +203,5 @@ async function addAttachment(file, dataurl) {
};
},
});
- console.log(file, dataurl, result);
- if (result instanceof Error) throw result;
return result;
}
diff --git a/apps/web/src/components/note/index.js b/apps/web/src/components/note/index.js
index beda3f4b0..76d5700d1 100644
--- a/apps/web/src/components/note/index.js
+++ b/apps/web/src/components/note/index.js
@@ -6,13 +6,10 @@ import ListItem from "../list-item";
import { showMoveNoteDialog } from "../../common/dialog-controller";
import { store, useStore } from "../../stores/note-store";
import { db } from "../../common/db";
-import { showExportDialog } from "../../common/dialog-controller";
-import { showItemDeletedToast } from "../../common/toasts";
import { showUnpinnedToast } from "../../common/toasts";
import { showToast } from "../../utils/toast";
import { hashNavigate, navigate } from "../../navigation";
import { showPublishView } from "../publish-view";
-import Vault from "../../common/vault";
import IconTag from "../icon-tag";
import { COLORS } from "../../common";
import { exportNotes } from "../../common/export";