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