mirror of
https://github.com/zadam/trilium.git
synced 2025-11-11 15:55:52 +01:00
feat(react/settings): port sync options
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import type { InputHTMLAttributes, RefObject } from "preact/compat";
|
||||
import FormText from "./FormText";
|
||||
|
||||
interface FormTextBoxProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "onChange" | "value"> {
|
||||
id?: string;
|
||||
@@ -11,9 +10,11 @@ interface FormTextBoxProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "
|
||||
export default function FormTextBox({ inputRef, className, type, currentValue, onChange, ...rest}: FormTextBoxProps) {
|
||||
if (type === "number" && currentValue) {
|
||||
const { min, max } = rest;
|
||||
if (min && currentValue < min) {
|
||||
console.log(currentValue , min, max);
|
||||
const currentValueNum = parseInt(currentValue, 10);
|
||||
if (min && currentValueNum < parseInt(String(min), 10)) {
|
||||
currentValue = String(min);
|
||||
} else if (max && currentValue > max) {
|
||||
} else if (max && currentValueNum > parseInt(String(max), 10)) {
|
||||
currentValue = String(max);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user