fix(note_language): crash if user entered invalid locale

This commit is contained in:
Elian Doran 2025-03-04 18:38:07 +02:00
parent bb42b5fb19
commit b81fd69981
No known key found for this signature in database

View File

@ -16,6 +16,11 @@ const TPL = `\
</div>
`;
const DEFAULT_LOCALE: Locale = {
id: "",
name: t("note_language.not_set")
};
export default class NoteLanguageWidget extends NoteContextAwareWidget {
private dropdown!: Dropdown;
@ -27,10 +32,7 @@ export default class NoteLanguageWidget extends NoteContextAwareWidget {
constructor() {
super();
this.locales = [
{
id: "",
name: t("note_language.not_set")
},
DEFAULT_LOCALE,
"---",
...getAvailableLocales()
];
@ -81,7 +83,7 @@ export default class NoteLanguageWidget extends NoteContextAwareWidget {
async refreshWithNote(note: FNote) {
const languageId = note.getLabelValue("language") ?? "";
const language = this.locales.find((l) => (typeof l === "object" && l.id === languageId)) as Locale;
const language = (this.locales.find((l) => (typeof l === "object" && l.id === languageId)) as Locale | null) ?? DEFAULT_LOCALE;
this.$noteLanguageDesc.text(language.name);
}