diff --git a/apps/client/src/services/options.ts b/apps/client/src/services/options.ts index c1590721f..9a97153d0 100644 --- a/apps/client/src/services/options.ts +++ b/apps/client/src/services/options.ts @@ -1,7 +1,7 @@ import server from "./server.js"; import { isShare } from "./utils.js"; -type OptionValue = number | string; +export type OptionValue = number | string; class Options { initializedPromise: Promise; diff --git a/apps/client/src/widgets/react/FormSelect.tsx b/apps/client/src/widgets/react/FormSelect.tsx index f068adcda..ce42c4815 100644 --- a/apps/client/src/widgets/react/FormSelect.tsx +++ b/apps/client/src/widgets/react/FormSelect.tsx @@ -65,7 +65,7 @@ function FormSelectGroup({ values, keyProperty, titleProperty, currentValue } return ( diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsx index 1c6707a67..04ae86ef2 100644 --- a/apps/client/src/widgets/react/hooks.tsx +++ b/apps/client/src/widgets/react/hooks.tsx @@ -3,7 +3,7 @@ import { EventData, EventNames } from "../../components/app_context"; import { ParentComponent } from "./ReactBasicWidget"; import SpacedUpdate from "../../services/spaced_update"; import { OptionNames } from "@triliumnext/commons"; -import options from "../../services/options"; +import options, { type OptionValue } from "../../services/options"; import utils, { reloadFrontendApp } from "../../services/utils"; import Component from "../../components/component"; @@ -99,12 +99,12 @@ export function useSpacedUpdate(callback: () => Promise, interval = 1000) return spacedUpdateRef.current; } -export function useTriliumOption(name: OptionNames, needsRefresh?: boolean): [string, (newValue: string) => Promise] { +export function useTriliumOption(name: OptionNames, needsRefresh?: boolean): [string, (newValue: OptionValue) => Promise] { const initialValue = options.get(name); const [ value, setValue ] = useState(initialValue); const wrappedSetValue = useMemo(() => { - return async (newValue: string) => { + return async (newValue: OptionValue) => { await options.save(name, newValue); if (needsRefresh) { @@ -134,6 +134,14 @@ export function useTriliumOptionBool(name: OptionNames): [boolean, (newValue: bo ] } +export function useTriliumOptionInt(name: OptionNames): [number, (newValue: number) => Promise] { + const [ value, setValue ] = useTriliumOption(name); + return [ + (parseInt(value, 10)), + (newValue) => setValue(newValue) + ] +} + /** * Generates a unique name via a random alphanumeric string of a fixed length. * diff --git a/apps/client/src/widgets/type_widgets/options/i18n.tsx b/apps/client/src/widgets/type_widgets/options/i18n.tsx index 95ea8af75..c965d8e7e 100644 --- a/apps/client/src/widgets/type_widgets/options/i18n.tsx +++ b/apps/client/src/widgets/type_widgets/options/i18n.tsx @@ -3,7 +3,7 @@ import { getAvailableLocales, t } from "../../../services/i18n"; import FormSelect from "../../react/FormSelect"; import OptionsRow from "./components/OptionsRow"; import OptionsSection from "./components/OptionsSection"; -import { useTriliumOption } from "../../react/hooks"; +import { useTriliumOption, useTriliumOptionInt } from "../../react/hooks"; import type { Locale } from "@triliumnext/commons"; import { isElectron } from "../../../services/utils"; import FormRadioGroup from "../../react/FormRadioGroup"; @@ -54,7 +54,7 @@ function LocaleSelector({ locales, currentValue, onChange }: { locales: Locale[] function DateSettings() { const [ firstDayOfWeek, setFirstDayOfWeek ] = useTriliumOption("firstDayOfWeek"); const [ firstWeekOfYear, setFirstWeekOfYear ] = useTriliumOption("firstWeekOfYear"); - const [ minDaysInFirstWeek, setMinDaysInFirstWeek ] = useTriliumOption("minDaysInFirstWeek"); + const [ minDaysInFirstWeek, setMinDaysInFirstWeek ] = useTriliumOptionInt("minDaysInFirstWeek"); return ( <> diff --git a/apps/client/src/widgets/type_widgets/options/i18n/i18n.ts b/apps/client/src/widgets/type_widgets/options/i18n/i18n.ts index 53e509462..0106ae227 100644 --- a/apps/client/src/widgets/type_widgets/options/i18n/i18n.ts +++ b/apps/client/src/widgets/type_widgets/options/i18n/i18n.ts @@ -67,20 +67,8 @@ const TPL = /*html*/` export default class LocalizationOptions extends OptionsWidget { - private $formattingLocaleSelect!: JQuery; - private $minDaysRow!: JQuery; - doRender() { this.$widget = $(TPL); - - this.$minDaysRow = this.$widget.find(".min-days-row"); - - this.$widget.find('input[name="first-week-of-year"]').on('change', (e) => { - const target = e.target as HTMLInputElement; - const value = parseInt(target.value); - this.updateOption("firstWeekOfYear", value); - }); - this.$widget.find(".restart-app-button").on("click", utils.restartDesktopApp); }