From 4ef6169041b1e934a17493aa399de60aaad8ae32 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Mon, 18 Aug 2025 12:11:29 +0300 Subject: [PATCH] feat(react/settings): port highlight list settings --- .../options/components/CheckboxList.tsx | 2 - .../type_widgets/options/text_notes.tsx | 30 +++++++++- .../options/text_notes/highlights_list.ts | 56 ------------------- 3 files changed, 29 insertions(+), 59 deletions(-) delete mode 100644 apps/client/src/widgets/type_widgets/options/text_notes/highlights_list.ts diff --git a/apps/client/src/widgets/type_widgets/options/components/CheckboxList.tsx b/apps/client/src/widgets/type_widgets/options/components/CheckboxList.tsx index fedfe1d86..66b17dd48 100644 --- a/apps/client/src/widgets/type_widgets/options/components/CheckboxList.tsx +++ b/apps/client/src/widgets/type_widgets/options/components/CheckboxList.tsx @@ -1,5 +1,3 @@ -import { useEffect, useState } from "preact/hooks"; - interface CheckboxListProps { values: T[]; keyProperty: keyof T; diff --git a/apps/client/src/widgets/type_widgets/options/text_notes.tsx b/apps/client/src/widgets/type_widgets/options/text_notes.tsx index 49f39e6de..9f63315b8 100644 --- a/apps/client/src/widgets/type_widgets/options/text_notes.tsx +++ b/apps/client/src/widgets/type_widgets/options/text_notes.tsx @@ -2,7 +2,7 @@ import { useEffect, useMemo, useState } from "preact/hooks"; import { t } from "../../../services/i18n"; import FormCheckbox from "../../react/FormCheckbox"; import FormRadioGroup from "../../react/FormRadioGroup"; -import { useTriliumOption, useTriliumOptionBool } from "../../react/hooks"; +import { useTriliumOption, useTriliumOptionBool, useTriliumOptionJson } from "../../react/hooks"; import OptionsSection from "./components/OptionsSection"; import { toggleBodyClass } from "../../../services/utils"; import FormGroup from "../../react/FormGroup"; @@ -15,6 +15,7 @@ import { getHtml } from "../../react/RawHtml"; import { CSSProperties } from "preact/compat"; import FormText from "../../react/FormText"; import { FormTextBoxWithUnit } from "../../react/FormTextBox"; +import CheckboxList from "./components/CheckboxList"; export default function TextNoteSettings() { return ( @@ -24,6 +25,7 @@ export default function TextNoteSettings() { + ) } @@ -251,4 +253,30 @@ function TableOfContent() { {t("table_of_contents.shortcut_info")} ) +} + +function HighlightsList() { + const [ highlightsList, setHighlightsList ] = useTriliumOptionJson("highlightsList"); + + return ( + + {t("highlights_list.description")} + +
+ +
{t("highlights_list.visibility_title")}
+ {t("highlights_list.visibility_description")} + {t("highlights_list.shortcut_info")} +
+ ) } \ No newline at end of file diff --git a/apps/client/src/widgets/type_widgets/options/text_notes/highlights_list.ts b/apps/client/src/widgets/type_widgets/options/text_notes/highlights_list.ts deleted file mode 100644 index b54bd635a..000000000 --- a/apps/client/src/widgets/type_widgets/options/text_notes/highlights_list.ts +++ /dev/null @@ -1,56 +0,0 @@ -import OptionsWidget from "../options_widget.js"; -import { t } from "../../../../services/i18n.js"; -import type { OptionMap } from "@triliumnext/commons"; - -const TPL = /*html*/` -
-

${t("highlights_list.title")}

- -

${t("highlights_list.description")}

- -
- - - - - -
- -
- -
${t("highlights_list.visibility_title")}
- -

${t("highlights_list.visibility_description")}

- -

${t("highlights_list.shortcut_info")}

-
`; - -export default class HighlightsListOptions extends OptionsWidget { - - private $hlt!: JQuery; - - doRender() { - this.$widget = $(TPL); - this.$hlt = this.$widget.find("input.highlights-list-check"); - this.$hlt.on("change", () => { - const hltVals = this.$widget - .find('input.highlights-list-check[type="checkbox"]:checked') - .map(function () { - return (this as HTMLInputElement).value; - }) - .get(); - this.updateOption("highlightsList", JSON.stringify(hltVals)); - }); - } - - async optionsLoaded(options: OptionMap) { - const hltVals = JSON.parse(options.highlightsList); - this.$widget.find('input.highlights-list-check[type="checkbox"]').each(function () { - if ($.inArray($(this).val(), hltVals) !== -1) { - $(this).prop("checked", true); - } else { - $(this).prop("checked", false); - } - }); - } -}