refactor(client/options): deduplicate editor feature checkbox

This commit is contained in:
Elian Doran 2025-09-23 20:14:15 +03:00
parent 97b5ea0798
commit 71ce9c459e
No known key found for this signature in database

View File

@ -10,7 +10,7 @@ import Column from "../../react/Column";
import { FormSelectGroup, FormSelectWithGroups } from "../../react/FormSelect";
import { Themes } from "@triliumnext/highlightjs";
import { ensureMimeTypesForHighlighting, loadHighlightingTheme } from "../../../services/syntax_highlight";
import { normalizeMimeTypeForCKEditor } from "@triliumnext/commons";
import { normalizeMimeTypeForCKEditor, type OptionNames } from "@triliumnext/commons";
import { getHtml } from "../../react/RawHtml";
import type { CSSProperties } from "preact/compat";
import FormText from "../../react/FormText";
@ -69,26 +69,25 @@ function FormattingToolbar() {
}
function EditorFeatures() {
const [ textNoteEmojiCompletionEnabled, setTextNoteEmojiCompletionEnabled] = useTriliumOptionBool("textNoteEmojiCompletionEnabled");
const [ textNoteCompletionEnabled, setTextNoteCompletionEnabled ] = useTriliumOptionBool("textNoteCompletionEnabled");
return (
<OptionsSection title={t("editorfeatures.title")}>
<FormCheckbox
name="emoji-completion-enabled"
label={t("editorfeatures.emoji_completion_enabled")}
currentValue={textNoteEmojiCompletionEnabled} onChange={setTextNoteEmojiCompletionEnabled}
/>
<FormCheckbox
name="note-completion-enabled"
label={t("editorfeatures.note_completion_enabled")}
currentValue={textNoteCompletionEnabled} onChange={setTextNoteCompletionEnabled}
/>
<EditorFeature name="emoji-completion-enabled" optionName="textNoteEmojiCompletionEnabled" label={t("editorfeatures.emoji_completion_enabled")} />
<EditorFeature name="note-completion-enabled" optionName="textNoteCompletionEnabled" label={t("editorfeatures.note_completion_enabled")} />
</OptionsSection>
);
}
function EditorFeature({ optionName, name, label }: { optionName: OptionNames, name: string, label: string }) {
const [ featureEnabled, setFeatureEnabled ] = useTriliumOptionBool(optionName);
return (
<FormCheckbox
name={name} label={label}
currentValue={featureEnabled} onChange={setFeatureEnabled}
/>
);
}
function HeadingStyle() {
const [ headingStyle, setHeadingStyle ] = useTriliumOption("headingStyle");