From b2db35982f79961edaac95ac00561048e0765023 Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Fri, 19 Jul 2019 09:48:36 -0600 Subject: [PATCH] Update addWords() to not save; Update importWords to save after complete --- src/js/dictionaryManagement.js | 9 +++++++-- src/js/utilities.js | 1 - src/js/wordManagement.js | 17 +++++++++-------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/js/dictionaryManagement.js b/src/js/dictionaryManagement.js index 85ac09d..b71f7e5 100644 --- a/src/js/dictionaryManagement.js +++ b/src/js/dictionaryManagement.js @@ -245,13 +245,18 @@ export function importWords() { definition: removeTags(row.definition).trim(), details: removeTags(row.explanation).trim(), wordId: getNextId(), - }, false, false, false); + }, false); importedWords.push(importedWord); + + // Sort and save every 500 words, just in case something goes wrong on large imports + if (importedWords.length % 500 == 499) { + sortWords(false); + } } }, complete: () => { - saveDictionary(false); + sortWords(false); renderAll(); importWordsField.value = ''; document.getElementById('editModal').style.display = 'none'; diff --git a/src/js/utilities.js b/src/js/utilities.js index a82f4b3..7e5ef7f 100644 --- a/src/js/utilities.js +++ b/src/js/utilities.js @@ -1,4 +1,3 @@ -import { addWord } from './wordManagement'; import { getCookie } from './StackOverflow/cookie'; export function getNextId() { diff --git a/src/js/wordManagement.js b/src/js/wordManagement.js index db36044..bfe5b42 100644 --- a/src/js/wordManagement.js +++ b/src/js/wordManagement.js @@ -173,6 +173,14 @@ export function submitWordForm() { if (validateWord(word)) { addWord(word); + sortWords(true); + + if (upload && hasToken()) { + import('./account/index.js').then(account => { + account.uploadWord(word); + }); + } + clearWordForm(); } } @@ -187,7 +195,7 @@ export function clearWordForm() { document.getElementById('wordName').focus(); } -export function addWord(word, render = true, message = true, upload = true) { +export function addWord(word, message = true) { const timestamp = getTimestampInSeconds(); word.lastUpdated = timestamp; word.createdOn = timestamp; @@ -195,13 +203,6 @@ export function addWord(word, render = true, message = true, upload = true) { if (message) { addMessage(`${word.name} Created Successfully`, 30000); } - sortWords(render); - - if (upload && hasToken()) { - import('./account/index.js').then(account => { - account.uploadWord(word); - }); - } return word; }