chore(react/ribbon): fix event

This commit is contained in:
Elian Doran
2025-08-22 15:11:12 +03:00
parent 8e29b5eed6
commit eff5b6459d
2 changed files with 33 additions and 4 deletions

View File

@@ -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.
*