feat(options/advanced): automatically refresh

This commit is contained in:
Elian Doran 2025-12-10 12:29:12 +02:00
parent 4031332b98
commit c4f483c250
No known key found for this signature in database
2 changed files with 8 additions and 7 deletions

View File

@ -201,7 +201,7 @@ export function useTriliumOptionBool(name: OptionNames, needsRefresh?: boolean):
return [
(value === "true"),
(newValue) => setValue(newValue ? "true" : "false")
]
];
}
/**
@ -217,17 +217,18 @@ export function useTriliumOptionInt(name: OptionNames): [number, (newValue: numb
return [
(parseInt(value, 10)),
(newValue) => setValue(newValue)
]
];
}
/**
* Similar to {@link useTriliumOption}, but the object value is parsed to and from a JSON instead of a string.
*
* @param name the name of the option to listen for.
* @param needsRefresh whether to reload the frontend whenever the value is changed.
* @returns an array where the first value is the current option value and the second value is the setter.
*/
export function useTriliumOptionJson<T>(name: OptionNames): [ T, (newValue: T) => Promise<void> ] {
const [ value, setValue ] = useTriliumOption(name);
export function useTriliumOptionJson<T>(name: OptionNames, needsRefresh?: boolean): [ T, (newValue: T) => Promise<void> ] {
const [ value, setValue ] = useTriliumOption(name, needsRefresh);
useDebugValue(name);
return [
(JSON.parse(value) as T),

View File

@ -158,7 +158,7 @@ function ExistingAnonymizedDatabases({ databases }: { databases: AnonymizedDbRes
))}
</tbody>
</table>
)
);
}
function VacuumDatabaseOptions() {
@ -175,11 +175,11 @@ function VacuumDatabaseOptions() {
}}
/>
</OptionsSection>
)
);
}
function ExperimentalOptions() {
const [ enabledExperimentalFeatures, setEnabledExperimentalFeatures ] = useTriliumOptionJson<string[]>("experimentalFeatures");
const [ enabledExperimentalFeatures, setEnabledExperimentalFeatures ] = useTriliumOptionJson<string[]>("experimentalFeatures", true);
return (
<OptionsSection title={t("experimental_features.title")}>