8000 Add guard clauses against `dictionaryInfo.count` being nullable by jamesmaa · Pull Request #1651 · yomidevs/yomitan · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add guard clauses against dictionaryInfo.count being nullable #1651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ext/js/dictionary/dictionary-data-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export function groupTermFrequencies(dictionaryEntry, dictionaryInfo) {
});
}
const currentDictionaryInfo = dictionaryInfo.find(({title}) => title === dictionary);
const freqCount = currentDictionaryInfo?.counts.termMeta.freq ?? 0;
const freqCount = currentDictionaryInfo?.counts?.termMeta.freq ?? 0;
results.push({dictionary, frequencies, dictionaryAlias, freqCount});
}
return results;
Expand Down Expand Up @@ -138,7 +138,7 @@ export function groupKanjiFrequencies(sourceFrequencies, dictionaryInfo) {
});
}
const currentDictionaryInfo = dictionaryInfo.find(({title}) => title === dictionary);
const freqCount = currentDictionaryInfo?.counts.kanjiMeta.freq ?? 0;
const freqCount = currentDictionaryInfo?.counts?.kanjiMeta.freq ?? 0;
results.push({dictionary, frequencies, dictionaryAlias, freqCount});
}
return results;
Expand Down
8 changes: 4 additions & 4 deletions ext/js/display/display-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ export class DisplayGenerator {
dictionaryContentArray.push('URL: ' + currentDictionaryInfo.url);
}

const totalTerms = currentDictionaryInfo.counts.terms.total;
if (totalTerms > 0) {
const totalTerms = currentDictionaryInfo?.counts?.terms?.total;
if (!!totalTerms && totalTerms > 0) {
dictionaryContentArray.push('Term Count: ' + totalTerms.toString());
}

Expand Down Expand Up @@ -218,8 +218,8 @@ export class DisplayGenerator {
dictionaryContentArray.push('URL: ' + currentDictionaryInfo.url);
}

const totalKanji = currentDictionaryInfo.counts.kanji.total;
if (totalKanji > 0) {
const totalKanji = currentDictionaryInfo?.counts?.kanji?.total;
if (!!totalKanji && totalKanji > 0) {
dictionaryContentArray.push('Kanji Count: ' + totalKanji.toString());
}

Expand Down
4 changes: 2 additions & 2 deletions ext/js/pages/settings/dictionary-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,10 @@ class DictionaryEntry {
outdateElement.hidden = (version >= 3);
countsElement.textContent = this._counts !== null ? JSON.stringify(this._counts, null, 4) : '';
wildcardSupportedElement.checked = prefixWildcardsSupported;
partsOfSpeechFilterSetting.hidden = !counts.terms.total;
partsOfSpeechFilterSetting.hidden = !counts?.terms.total;
partsOfSpeechFilterToggle.dataset.setting = `dictionaries[${this._index}].partsOfSpeechFilter`;

useDeinflectionsSetting.hidden = !counts.terms.total;
useDeinflectionsSetting.hidden = !counts?.terms.total;
useDeinflectionsToggle.dataset.setting = `dictionaries[${this._index}].useDeinflections`;

this._setupDetails(detailsTableElement);
Expand Down
2 changes: 1 addition & 1 deletion types/ext/dictionary-importer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export type Summary = {
version: number;
importDate: number;
prefixWildcardsSupported: boolean;
counts: SummaryCounts;
counts?: SummaryCounts;
styles: string;
isUpdatable?: boolean;
indexUrl?: string;
Expand Down
Loading
0