mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 23:29:02 +02:00
feat(react/settings): react to property change
This commit is contained in:
parent
fbc1af56ed
commit
e0e7bd42cc
@ -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
|
||||
]
|
||||
}
|
@ -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")}>
|
||||
|
Loading…
x
Reference in New Issue
Block a user