From d4397fc4c1948bcc3c7ddf796a06eda5331b0c49 Mon Sep 17 00:00:00 2001 From: thecodrr Date: Wed, 20 Oct 2021 14:42:36 +0500 Subject: [PATCH] feat: cancel media downloads on note change/exit --- apps/web/src/stores/editor-store.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/web/src/stores/editor-store.js b/apps/web/src/stores/editor-store.js index 31da3a715..5eb95be7e 100644 --- a/apps/web/src/stores/editor-store.js +++ b/apps/web/src/stores/editor-store.js @@ -72,6 +72,7 @@ class EditorStore extends BaseStore { const session = this.get().session; + if (session.id) await db.fs.cancel(session.id); if (session.id === noteId && !force) return; if (session.state === SESSION_STATES.unlocked) { @@ -165,8 +166,11 @@ class EditorStore extends BaseStore { }); }; - newSession = (nonce) => { + newSession = async (nonce) => { let context = noteStore.get().context; + const session = this.get().session; + if (session.id) await db.fs.cancel(session.id); + this.set((state) => { state.session = { ...getDefaultSession(), @@ -179,7 +183,10 @@ class EditorStore extends BaseStore { appStore.setIsEditorOpen(true); }; - clearSession = (shouldNavigate = true) => { + clearSession = async (shouldNavigate = true) => { + const session = this.get().session; + if (session.id) await db.fs.cancel(session.id); + appStore.setIsEditorOpen(false); this.set((state) => { state.session = {