From 392447c117e4df80d6e19753b2169dacbf6666ff Mon Sep 17 00:00:00 2001 From: Aleix Soler Date: Wed, 6 Aug 2025 17:38:13 +0200 Subject: [PATCH] chore: add templates settings instead of predefined const --- components/SettingsUI/QuickCommandsSettings.tsx | 8 ++++---- components/SettingsUI/TemplateSettings.tsx | 6 ++---- components/SettingsUI/index.tsx | 8 +------- constants/defaultSettings.ts | 6 +++++- core/noteStatusService.ts | 6 +++--- types/pluginSettings.ts | 1 + 6 files changed, 16 insertions(+), 19 deletions(-) diff --git a/components/SettingsUI/QuickCommandsSettings.tsx b/components/SettingsUI/QuickCommandsSettings.tsx index af3fd1d..3f108ea 100644 --- a/components/SettingsUI/QuickCommandsSettings.tsx +++ b/components/SettingsUI/QuickCommandsSettings.tsx @@ -6,7 +6,6 @@ import { NoStatusesMessage } from "./NoStatusesMessage"; export type Props = { settings: PluginSettings; onChange: (key: keyof PluginSettings, value: unknown) => void; - templates: StatusTemplate[]; }; type GroupedStatuses = { @@ -20,7 +19,6 @@ type GroupedStatuses = { export const QuickCommandsSettings: React.FC = ({ settings, onChange, - templates, }) => { const groupedStatuses = useMemo((): GroupedStatuses => { const customStatuses = settings.customStatuses.filter( @@ -29,7 +27,9 @@ export const QuickCommandsSettings: React.FC = ({ const templateGroups = []; if (!settings.useCustomStatusesOnly) { for (const templateId of settings.enabledTemplates) { - const template = templates.find((t) => t.id === templateId); + const template = settings.templates.find( + (t) => t.id === templateId, + ); if (template) { const statuses = template.statuses.filter( (s) => s.name !== "unknown", @@ -41,7 +41,7 @@ export const QuickCommandsSettings: React.FC = ({ } } return { customStatuses, templateGroups }; - }, [settings, templates]); + }, [settings]); const currentQuickCommands = settings.quickStatusCommands || []; diff --git a/components/SettingsUI/TemplateSettings.tsx b/components/SettingsUI/TemplateSettings.tsx index 67d6756..72adbab 100644 --- a/components/SettingsUI/TemplateSettings.tsx +++ b/components/SettingsUI/TemplateSettings.tsx @@ -1,17 +1,15 @@ import React, { useCallback } from "react"; -import { PluginSettings, StatusTemplate } from "@/types/pluginSettings"; +import { PluginSettings } from "@/types/pluginSettings"; import { TemplateItem } from "./TemplateItem"; interface TemplateSettingsProps { settings: PluginSettings; onChange: (key: keyof PluginSettings, value: unknown) => void; - templates: StatusTemplate[]; } export const TemplateSettings: React.FC = ({ settings, onChange, - templates, }) => { const handleTemplateToggle = useCallback( (templateId: string, enabled: boolean) => { @@ -38,7 +36,7 @@ export const TemplateSettings: React.FC = ({ workflows

- {templates.map((template) => ( + {settings.templates.map((template) => ( = ({ settings, onChange }) => { return (
- +
); diff --git a/constants/defaultSettings.ts b/constants/defaultSettings.ts index ce52a3c..71d75ad 100644 --- a/constants/defaultSettings.ts +++ b/constants/defaultSettings.ts @@ -1,5 +1,8 @@ import { PluginSettings } from "types/pluginSettings"; -import { DEFAULT_ENABLED_TEMPLATES } from "./predefinedTemplates"; +import { + DEFAULT_ENABLED_TEMPLATES, + PREDEFINED_TEMPLATES, +} from "./predefinedTemplates"; export const DEFAULT_PLUGIN_SETTINGS: PluginSettings = { fileExplorerIconPosition: "absolute-right", @@ -12,6 +15,7 @@ export const DEFAULT_PLUGIN_SETTINGS: PluginSettings = { }, showStatusBar: true, autoHideStatusBar: false, + templates: [...PREDEFINED_TEMPLATES], customStatuses: [], showStatusIconsInExplorer: true, hideUnknownStatusInExplorer: true, // Default to hide unknown status diff --git a/core/noteStatusService.ts b/core/noteStatusService.ts index 998a64a..ab6553b 100644 --- a/core/noteStatusService.ts +++ b/core/noteStatusService.ts @@ -8,7 +8,6 @@ import { } from "@/types/noteStatus"; import settingsService from "@/core/settingsService"; import eventBus from "./eventBus"; -import { PREDEFINED_TEMPLATES } from "@/constants/predefinedTemplates"; export abstract class BaseNoteStatusService { static app: App; @@ -64,8 +63,9 @@ export abstract class BaseNoteStatusService { if (settingsService.settings.useCustomStatusesOnly) { return []; } - const enabledTemplates = PREDEFINED_TEMPLATES.filter((template) => - settingsService.settings.enabledTemplates.includes(template.id), + const enabledTemplates = settingsService.settings.templates.filter( + (template) => + settingsService.settings.enabledTemplates.includes(template.id), ); return enabledTemplates.flatMap((t) => t.statuses); } diff --git a/types/pluginSettings.ts b/types/pluginSettings.ts index d41945f..23c9dfb 100644 --- a/types/pluginSettings.ts +++ b/types/pluginSettings.ts @@ -15,6 +15,7 @@ export type PluginSettings = { statusColors: Record; showStatusBar: boolean; autoHideStatusBar: boolean; + templates: StatusTemplate[]; customStatuses: NoteStatus[]; showStatusIconsInExplorer: boolean; hideUnknownStatusInExplorer: boolean;