feat(react/settings): react to property change

This commit is contained in:
Elian Doran 2025-08-14 17:47:45 +03:00
parent fbc1af56ed
commit e0e7bd42cc
No known key found for this signature in database
2 changed files with 15 additions and 2 deletions

View File

@ -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
]
}

View File

@ -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")}>