mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	chore(react/ribbon): fix event
This commit is contained in:
		| @@ -166,6 +166,33 @@ export function useTriliumOption(name: OptionNames, needsRefresh?: boolean): [st | |||||||
|     ] |     ] | ||||||
| } | } | ||||||
|  |  | ||||||
|  | export function useTriliumOptionBeta(name: OptionNames, needsRefresh?: boolean): [string, (newValue: OptionValue) => Promise<void>] { | ||||||
|  |     const initialValue = options.get(name); | ||||||
|  |     const [ value, setValue ] = useState(initialValue); | ||||||
|  |  | ||||||
|  |     const wrappedSetValue = useMemo(() => { | ||||||
|  |         return async (newValue: OptionValue) => { | ||||||
|  |             await options.save(name, newValue); | ||||||
|  |  | ||||||
|  |             if (needsRefresh) { | ||||||
|  |                 reloadFrontendApp(`option change: ${name}`); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     }, [ name, needsRefresh ]); | ||||||
|  |  | ||||||
|  |     useTriliumEventBeta("entitiesReloaded", useCallback(({ loadResults }) => { | ||||||
|  |         if (loadResults.getOptionNames().includes(name)) { | ||||||
|  |             const newValue = options.get(name); | ||||||
|  |             setValue(newValue); | ||||||
|  |         } | ||||||
|  |      }, [ name ])); | ||||||
|  |  | ||||||
|  |     return [ | ||||||
|  |         value, | ||||||
|  |         wrappedSetValue | ||||||
|  |     ] | ||||||
|  | } | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Similar to {@link useTriliumOption}, but the value is converted to and from a boolean instead of a string. |  * Similar to {@link useTriliumOption}, but the value is converted to and from a boolean instead of a string. | ||||||
|  *  |  *  | ||||||
|   | |||||||
| @@ -3,7 +3,7 @@ import Dropdown from "../react/Dropdown"; | |||||||
| import { NOTE_TYPES } from "../../services/note_types"; | import { NOTE_TYPES } from "../../services/note_types"; | ||||||
| import { FormDropdownDivider, FormListBadge, FormListItem } from "../react/FormList"; | import { FormDropdownDivider, FormListBadge, FormListItem } from "../react/FormList"; | ||||||
| import { getAvailableLocales, t } from "../../services/i18n"; | import { getAvailableLocales, t } from "../../services/i18n"; | ||||||
| import { useNoteContext, useNoteLabel, useNoteLabelBoolean, useNoteProperty, useTriliumEventBeta, useTriliumOption, useTriliumOptionJson } from "../react/hooks"; | import { useNoteContext, useNoteLabel, useNoteLabelBoolean, useNoteProperty, useTriliumEventBeta, useTriliumOption, useTriliumOptionBeta, useTriliumOptionJson } from "../react/hooks"; | ||||||
| import mime_types from "../../services/mime_types"; | import mime_types from "../../services/mime_types"; | ||||||
| import { Locale, NoteType, ToggleInParentResponse } from "@triliumnext/commons"; | import { Locale, NoteType, ToggleInParentResponse } from "@triliumnext/commons"; | ||||||
| import server from "../../services/server"; | import server from "../../services/server"; | ||||||
| @@ -267,13 +267,13 @@ function SharedSwitch({ note }: { note?: FNote | null }) { | |||||||
| } | } | ||||||
|  |  | ||||||
| function NoteLanguageSwitch({ note }: { note?: FNote | null }) { | function NoteLanguageSwitch({ note }: { note?: FNote | null }) { | ||||||
|     const [ languages ] = useTriliumOption("languages"); |     const [ languages ] = useTriliumOptionBeta("languages"); | ||||||
|     const DEFAULT_LOCALE = { |     const DEFAULT_LOCALE = { | ||||||
|         id: "", |         id: "", | ||||||
|         name: t("note_language.not_set") |         name: t("note_language.not_set") | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     const [ currentNoteLanguage, setCurrentNoteLanguage ] = useNoteLabel(note, "language") ?? ""; |     const [ currentNoteLanguage, setCurrentNoteLanguage ] = useNoteLabel(note, "language"); | ||||||
|  |  | ||||||
|     const locales = useMemo(() => { |     const locales = useMemo(() => { | ||||||
|         const enabledLanguages = JSON.parse(languages ?? "[]") as string[]; |         const enabledLanguages = JSON.parse(languages ?? "[]") as string[]; | ||||||
| @@ -307,14 +307,16 @@ function NoteLanguageSwitch({ note }: { note?: FNote | null }) { | |||||||
|         return locales; |         return locales; | ||||||
|     }, [ languages ]); |     }, [ languages ]); | ||||||
|  |  | ||||||
|  |      | ||||||
|     return ( |     return ( | ||||||
|         <div className="note-language-container"> |         <div className="note-language-container"> | ||||||
|             <Dropdown> |             <Dropdown> | ||||||
|                 {locales.map(locale => { |                 {locales.map(locale => { | ||||||
|                     if (typeof locale === "object") { |                     if (typeof locale === "object") { | ||||||
|  |                         const checked = locale.id === (currentNoteLanguage ?? ""); | ||||||
|                         return <FormListItem |                         return <FormListItem | ||||||
|                             rtl={locale.rtl} |                             rtl={locale.rtl} | ||||||
|                             selected={locale.id === currentNoteLanguage} |                             checked={checked} | ||||||
|                             onClick={() => setCurrentNoteLanguage(locale.id)} |                             onClick={() => setCurrentNoteLanguage(locale.id)} | ||||||
|                         >{locale.name}</FormListItem> |                         >{locale.name}</FormListItem> | ||||||
|                     } else { |                     } else { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user