From 7d5a4044c70f6bfb90de766dff3b435a245db06c Mon Sep 17 00:00:00 2001 From: GaurangTandon <1gaurangtandon@gmail.com> Date: Mon, 24 Jun 2019 16:49:38 +0530 Subject: [PATCH] final corrections --- html/options.html | 2 +- js/options.js | 4 +++- js/snippetClasses.js | 12 +++++++++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/html/options.html b/html/options.html index 1d0fe25..d4d37fd 100644 --- a/html/options.html +++ b/html/options.html @@ -86,7 +86,7 @@
Oops, there's an error!
diff --git a/js/options.js b/js/options.js index ece9f42..3a3e4b1 100644 --- a/js/options.js +++ b/js/options.js @@ -468,7 +468,9 @@ These editors are generally found in your email client like Gmail, Outlook, etc. // an HTML element reader.addEventListener("load", (event) => { const importFileData = event.target.result; - console.log("Data got", importFileData); + console.log("Data got\n", importFileData); + window.Data = {}; + Data.snippets = new Folder(Folder.MAIN_SNIPPETS_NAME); initiateRestore(importFileData, Data.snippets, true); }); diff --git a/js/snippetClasses.js b/js/snippetClasses.js index 237b37a..731a9bd 100644 --- a/js/snippetClasses.js +++ b/js/snippetClasses.js @@ -269,9 +269,15 @@ Generic.isValidName = function (name, type) { return `Name cannot be greater than ${OBJECT_NAME_LIMIT} characters. Current name has ${name.length - OBJECT_NAME_LIMIT} more characters.`; } - return Data.snippets.getUniqueObject(name, type) - ? Generic.getDuplicateObjectsText(name, type) - : "true"; + + // error may occur during no-db-restore + try { + const dupeExists = Data.snippets.getUniqueObject(name, type); + if (dupeExists) { return Generic.getDuplicateObjectsText(name, type); } + return "true"; + } catch (e) { + return "true"; + } }; /**