fix anki network error dialog on search page, cleanup template

workaround
This commit is contained in:
Alex Yatskov 2017-08-18 21:14:09 -07:00
parent 922d2cd468
commit 30fe3d2506
3 changed files with 22 additions and 18 deletions

View File

@ -66,22 +66,29 @@ async function apiDefinitionAdd(definition, mode) {
}
async function apiDefinitionsAddable(definitions, modes) {
const notes = [];
for (const definition of definitions) {
for (const mode of modes) {
notes.push(dictNoteFormat(definition, mode, utilBackend().options));
}
}
const results = await utilBackend().anki.canAddNotes(notes);
const states = [];
for (let resultBase = 0; resultBase < results.length; resultBase += modes.length) {
const state = {};
for (let modeOffset = 0; modeOffset < modes.length; ++modeOffset) {
state[modes[modeOffset]] = results[resultBase + modeOffset];
try {
const notes = [];
for (const definition of definitions) {
for (const mode of modes) {
notes.push(dictNoteFormat(definition, mode, utilBackend().options));
}
}
states.push(state);
const results = await utilBackend().anki.canAddNotes(notes);
for (let resultBase = 0; resultBase < results.length; resultBase += modes.length) {
const state = {};
for (let modeOffset = 0; modeOffset < modes.length; ++modeOffset) {
state[modes[modeOffset]] = results[resultBase + modeOffset];
}
states.push(state);
}
return states;
} catch (e) {
// NOP
}
return states;

View File

@ -223,10 +223,7 @@ function dictFieldFormat(field, definition, mode, options) {
modeKanji: mode === 'kanji'
};
field = field.replace(
`{${marker}}`,
handlebarsRender('fields.html', data).trim()
);
field = field.replace(`{${marker}}`, handlebarsRender('fields.html', data));
}
return field;

View File

@ -51,5 +51,5 @@ function handlebarsRender(template, data) {
Handlebars.registerHelper('multiLine', handlebarsMultiLine);
}
return Handlebars.templates[template](data);
return Handlebars.templates[template](data).trim();
}