From f934318625783d217860f058011452e4a42793fa Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Mon, 18 Aug 2025 18:27:12 +0300 Subject: [PATCH] feat(react/settings): port revision snapshot list --- .../widgets/type_widgets/options/other.tsx | 37 +++++++++++++- .../options/other/revision_snapshots_limit.ts | 50 ------------------- 2 files changed, 36 insertions(+), 51 deletions(-) delete mode 100644 apps/client/src/widgets/type_widgets/options/other/revision_snapshots_limit.ts diff --git a/apps/client/src/widgets/type_widgets/options/other.tsx b/apps/client/src/widgets/type_widgets/options/other.tsx index 3ad95a55a..12bed4ee4 100644 --- a/apps/client/src/widgets/type_widgets/options/other.tsx +++ b/apps/client/src/widgets/type_widgets/options/other.tsx @@ -7,11 +7,12 @@ import FormText from "../../react/FormText"; import OptionsSection from "./components/OptionsSection"; import TimeSelector from "./components/TimeSelector"; import { useMemo } from "preact/hooks"; -import { useTriliumOptionBool, useTriliumOptionJson } from "../../react/hooks"; +import { useTriliumOption, useTriliumOptionBool, useTriliumOptionInt, useTriliumOptionJson } from "../../react/hooks"; import { SANITIZER_DEFAULT_ALLOWED_TAGS } from "@triliumnext/commons"; import FormCheckbox from "../../react/FormCheckbox"; import FormGroup from "../../react/FormGroup"; import search from "../../../services/search"; +import { FormTextBoxWithUnit } from "../../react/FormTextBox"; export default function OtherSettings() { return ( @@ -19,6 +20,7 @@ export default function OtherSettings() { + @@ -91,6 +93,39 @@ function RevisionSnapshotInterval() { ) } +function RevisionSnapshotLimit() { + const [ revisionSnapshotNumberLimit, setRevisionSnapshotNumberLimit ] = useTriliumOption("revisionSnapshotNumberLimit"); + + return ( + + {t("revisions_snapshot_limit.note_revisions_snapshot_limit_description")} + + + { + const newValue = parseInt(value, 10); + if (!isNaN(newValue) && newValue >= -1) { + setRevisionSnapshotNumberLimit(newValue); + } + }} + /> + + + -`; - -export default class RevisionSnapshotsLimitOptions extends OptionsWidget { - - private $revisionSnapshotsNumberLimit!: JQuery; - private $eraseExcessRevisionSnapshotsButton!: JQuery; - - doRender() { - this.$widget = $(TPL); - this.$revisionSnapshotsNumberLimit = this.$widget.find(".revision-snapshot-number-limit"); - this.$revisionSnapshotsNumberLimit.on("change", () => { - let revisionSnapshotNumberLimit = parseInt(String(this.$revisionSnapshotsNumberLimit.val()), 10); - if (!isNaN(revisionSnapshotNumberLimit) && revisionSnapshotNumberLimit >= -1) { - this.updateOption("revisionSnapshotNumberLimit", revisionSnapshotNumberLimit); - } - }); - this.$eraseExcessRevisionSnapshotsButton = this.$widget.find(".erase-excess-revision-snapshots-now-button"); - this.$eraseExcessRevisionSnapshotsButton.on("click", () => { - server.post("revisions/erase-all-excess-revisions").then(() => { - toastService.showMessage(t("revisions_snapshot_limit.erase_excess_revision_snapshots_prompt")); - }); - }); - } - - async optionsLoaded(options: OptionMap) { - this.$revisionSnapshotsNumberLimit.val(options.revisionSnapshotNumberLimit); - } -}