Update how source terms are navigated

This commit is contained in:
toasted-nutbread 2019-11-26 12:29:49 -05:00
parent c7cb1b3d9e
commit cb9f9b585a

View File

@ -58,23 +58,25 @@ class Display {
async onKanjiLookup(e) { async onKanjiLookup(e) {
try { try {
e.preventDefault(); e.preventDefault();
if (!this.context) { return; }
const link = e.target; const link = e.target;
this.windowScroll.toY(0); this.windowScroll.toY(0);
const context = { const context = {
source: { source: {
definitions: this.definitions, type: 'terms',
index: this.entryIndexFind(link), details: {
scroll: this.windowScroll.y definitions: this.definitions,
} context: Object.assign({}, this.context, {
index: this.entryIndexFind(link),
scroll: this.windowScroll.y
})
}
},
sentence: this.context.sentence,
url: this.context.url
}; };
if (this.context) {
context.sentence = this.context.sentence;
context.url = this.context.url;
context.source.source = this.context.source;
}
const definitions = await apiKanjiFind(link.textContent, this.getOptionsContext()); const definitions = await apiKanjiFind(link.textContent, this.getOptionsContext());
this.setContentKanji(definitions, context); this.setContentKanji(definitions, context);
} catch (error) { } catch (error) {
@ -99,12 +101,10 @@ class Display {
} }
async onTermLookup(e, {disableScroll, selectText, disableHistory}={}) { async onTermLookup(e, {disableScroll, selectText, disableHistory}={}) {
const termLookupResults = await this.termLookup(e);
if (!termLookupResults) {
return false;
}
try { try {
if (!this.context) { return; }
const termLookupResults = await this.termLookup(e);
if (!termLookupResults) { return; }
const {textSource, definitions} = termLookupResults; const {textSource, definitions} = termLookupResults;
const scannedElement = e.target; const scannedElement = e.target;
@ -113,26 +113,22 @@ class Display {
if (!disableScroll) { if (!disableScroll) {
this.windowScroll.toY(0); this.windowScroll.toY(0);
} }
let context;
if (disableHistory) {
const {url, source} = this.context || {};
context = {sentence, url, source, disableScroll};
} else {
context = {
disableScroll,
source: {
definitions: this.definitions,
index: this.entryIndexFind(scannedElement),
scroll: this.windowScroll.y
}
};
if (this.context) { const context = {
context.sentence = sentence; source: disableHistory ? this.context.source : {
context.url = this.context.url; type: 'terms',
context.source.source = this.context.source; details: {
} definitions: this.definitions,
} context: Object.assign({}, this.context, {
index: this.entryIndexFind(scannedElement),
scroll: this.windowScroll.y
})
}
},
disableScroll,
sentence,
url: this.context.url
};
this.setContentTerms(definitions, context); this.setContentTerms(definitions, context);
@ -501,17 +497,9 @@ class Display {
} }
sourceTermView() { sourceTermView() {
if (this.context && this.context.source) { if (!this.context || !this.context.source) { return; }
const context = { const {type, details} = this.context.source;
url: this.context.source.url, this.setContent(type, details);
sentence: this.context.source.sentence,
index: this.context.source.index,
scroll: this.context.source.scroll,
source: this.context.source.source
};
this.setContentTerms(this.context.source.definitions, context);
}
} }
noteTryAdd(mode) { noteTryAdd(mode) {