mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	fix(note_language): crash if user entered invalid locale
This commit is contained in:
		| @@ -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); | ||||
|     } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user