code cosmetics: simplify import::undo

This commit is contained in:
tophf 2017-04-21 13:57:01 +03:00
parent 3b433adb42
commit fc7793453c

View File

@ -194,15 +194,18 @@ function importFromString(jsonString) {
...stats.codeOnly.ids, ...stats.codeOnly.ids,
...stats.added.ids, ...stats.added.ids,
]; ];
let resolve;
index = 0; index = 0;
return new Promise(undoNextId) return new Promise(resolve_ => {
.then(BG.refreshAllTabs) resolve = resolve_;
undoNextId();
}).then(BG.refreshAllTabs)
.then(() => messageBox({ .then(() => messageBox({
title: t('importReportUndoneTitle'), title: t('importReportUndoneTitle'),
contents: newIds.length + ' ' + t('importReportUndone'), contents: newIds.length + ' ' + t('importReportUndone'),
buttons: [t('confirmOK')], buttons: [t('confirmOK')],
})); }));
function undoNextId(resolve) { function undoNextId() {
if (index == newIds.length) { if (index == newIds.length) {
resolve(); resolve();
return; return;
@ -211,13 +214,10 @@ function importFromString(jsonString) {
deleteStyleSafe({id, notify: false}).then(id => { deleteStyleSafe({id, notify: false}).then(id => {
const oldStyle = oldStylesById.get(id); const oldStyle = oldStylesById.get(id);
if (oldStyle) { if (oldStyle) {
saveStyleSafe(Object.assign(oldStyle, { saveStyleSafe(Object.assign(oldStyle, SAVE_OPTIONS))
reason: 'import', .then(undoNextId);
notify: false,
})).then(() =>
setTimeout(undoNextId, 0, resolve));
} else { } else {
setTimeout(undoNextId, 0, resolve); undoNextId();
} }
}); });
} }