feat(react/settings): port sync options

This commit is contained in:
Elian Doran
2025-08-15 11:21:19 +03:00
parent c368ec3c38
commit f62078d02b
6 changed files with 110 additions and 132 deletions

View File

@@ -6,6 +6,7 @@ import { OptionNames } from "@triliumnext/commons";
import options, { type OptionValue } from "../../services/options";
import utils, { reloadFrontendApp } from "../../services/utils";
import Component from "../../components/component";
import server from "../../services/server";
type TriliumEventHandler<T extends EventNames> = (data: EventData<T>) => void;
const registeredHandlers: Map<Component, Map<EventNames, TriliumEventHandler<any>[]>> = new Map();
@@ -150,6 +151,19 @@ export function useTriliumOptionJson<T>(name: OptionNames): [ T, (newValue: T) =
];
}
export function useTriliumOptions<T extends OptionNames>(...names: T[]) {
const values: Record<string, string> = {};
for (const name of names) {
values[name] = options.get(name);
}
const setValue = (newValues: Record<T, string>) => server.put<void>("options", newValues);
return [
values as Record<T, string>,
setValue
] as const;
}
/**
* Generates a unique name via a random alphanumeric string of a fixed length.
*