From 253da36755f24d656664ca524808e3292eef3697 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 13 Nov 2016 17:50:09 -0800 Subject: WIP --- ext/bg/js/database.js | 5 +++-- ext/bg/js/options-form.js | 10 ++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'ext/bg/js') diff --git a/ext/bg/js/database.js b/ext/bg/js/database.js index 23041e40..5931e172 100644 --- a/ext/bg/js/database.js +++ b/ext/bg/js/database.js @@ -153,13 +153,14 @@ class Database { } return Promise.all([termCounter, kanjiCounter]).then(([termCount, kanjiCount]) => { + const rowLimit = 500; const totalCount = termCount + kanjiCount; let deletedCount = 0; let termDeleter = Promise.resolve(); if (info.hasTerms) { const termDeleterFunc = () => { - return this.db.terms.where('dictionary').equals(title).limit(500).delete().then(count => { + return this.db.terms.where('dictionary').equals(title).limit(rowLimit).delete().then(count => { if (count === 0) { return Promise.resolve(); } @@ -179,7 +180,7 @@ class Database { let kanjiDeleter = Promise.resolve(); if (info.hasKanji) { const kanjiDeleterFunc = () => { - return this.db.kanji.where('dictionary').equals(title).limit(500).delete().then(count => { + return this.db.kanji.where('dictionary').equals(title).limit(rowLimit).delete().then(count => { if (count === 0) { return Promise.resolve(); } diff --git a/ext/bg/js/options-form.js b/ext/bg/js/options-form.js index 2cabe162..015c9a0a 100644 --- a/ext/bg/js/options-form.js +++ b/ext/bg/js/options-form.js @@ -158,15 +158,17 @@ function onDictionaryImport() { const dictSpinner = $('#dict-spinner'); dictSpinner.show(); - const callback = (total, current) => { - dictProgress.find('div').css('width', `${current / total * 100.0}%`); + const setProgress = percent => { + dictProgress.find('div').css('width', `${percent}%`); }; + setProgress(0.0); + const dictUrl = $('#dict-url'); loadOptions().then(opts => { - database().importDictionary(dictUrl.val(), callback).then(summary => { + database().importDictionary(dictUrl.val(), (total, current) => setProgress(current / total * 100.0)).then(summary => { opts.dictionaries[summary.title] = {enableTerms: summary.hasTerms, enableKanji: summary.hasKanji}; - return saveOptions(opts); + return saveOptions(opts).then(() => yomichan().setOptions(opts)); }).then(() => { return populateDictionaries(opts); }).catch(error => { -- cgit v1.2.3