Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(react/settings): react to property change
Elian Dorane0e7bd42cc1f
diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsxindex 1af5485b3e..885049b9cb 100644--- a/apps/client/src/widgets/react/hooks.tsx+++ b/apps/client/src/widgets/react/hooks.tsx@@ -67,12 +67,24 @@ export function useSpacedUpdate(callback: () => Promise<void>, interval = 1000)return spacedUpdateRef.current;}-export function useTriliumOption(name: OptionNames): [string, Dispatch<StateUpdater<string>>] {+export function useTriliumOption(name: OptionNames): [string, (newValue: string) => void] {const initialValue = options.get(name);const [ value, setValue ] = useState(initialValue);+ function wrappedSetValue(newValue: string) {+ options.save(name, newValue);+ };++ useTriliumEvent("entitiesReloaded", ({ loadResults }) => {+ if (loadResults.getOptionNames().includes(name)) {+ const newValue = options.get(name);+ console.log("Got entities reloaded for option ", name, "value", newValue);+ setValue(newValue);+ }+ });+return [value,- setValue+ wrappedSetValue]}\ No newline at end of filediff --git a/apps/client/src/widgets/type_widgets/options/appearance.tsx b/apps/client/src/widgets/type_widgets/options/appearance.tsxindex ee95e15b1f..f3f48827f6 100644--- a/apps/client/src/widgets/type_widgets/options/appearance.tsx+++ b/apps/client/src/widgets/type_widgets/options/appearance.tsx@@ -5,6 +5,7 @@ import OptionsSection from "./components/OptionsSection";export default function AppearanceSettings() {const [ layoutOrientation, setLayoutOrientation ] = useTriliumOption("layoutOrientation");+ console.log("Render with ", layoutOrientation);return (<OptionsSection title={t("theme.layout")}>