From f5f4ec7528b2d45fbcbf2df527b817391af99a8e Mon Sep 17 00:00:00 2001 From: dwelle Date: Sat, 12 Jun 2021 22:52:59 +0200 Subject: [PATCH] remove `fileHandle` from IDB if user rejects permission --- src/actions/actionExport.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/actions/actionExport.tsx b/src/actions/actionExport.tsx index 093763285..de460f895 100644 --- a/src/actions/actionExport.tsx +++ b/src/actions/actionExport.tsx @@ -150,9 +150,21 @@ export const actionSaveToActiveFile = register({ if (error?.name !== "AbortError") { console.error(error); } + + if (fileHandleExists && error.name === "AbortError") { + try { + await idb.del(IDB_KEYS.fileHandle); + } catch (error) { + console.error(error); + } + return { + commitToHistory: false, + appState: { ...appState, fileHandle: null }, + }; + } + return { commitToHistory: false, - appState: { ...appState, fileHandle: null }, }; } },