mirror of
https://github.com/devonthesofa/obsidian-note-status.git
synced 2026-07-22 05:45:04 +00:00
chore: add templates settings instead of predefined const
This commit is contained in:
parent
c2808824a5
commit
392447c117
6 changed files with 16 additions and 19 deletions
|
|
@ -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<Props> = ({
|
||||
settings,
|
||||
onChange,
|
||||
templates,
|
||||
}) => {
|
||||
const groupedStatuses = useMemo((): GroupedStatuses => {
|
||||
const customStatuses = settings.customStatuses.filter(
|
||||
|
|
@ -29,7 +27,9 @@ export const QuickCommandsSettings: React.FC<Props> = ({
|
|||
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<Props> = ({
|
|||
}
|
||||
}
|
||||
return { customStatuses, templateGroups };
|
||||
}, [settings, templates]);
|
||||
}, [settings]);
|
||||
|
||||
const currentQuickCommands = settings.quickStatusCommands || [];
|
||||
|
||||
|
|
|
|||
|
|
@ -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<TemplateSettingsProps> = ({
|
||||
settings,
|
||||
onChange,
|
||||
templates,
|
||||
}) => {
|
||||
const handleTemplateToggle = useCallback(
|
||||
(templateId: string, enabled: boolean) => {
|
||||
|
|
@ -38,7 +36,7 @@ export const TemplateSettings: React.FC<TemplateSettingsProps> = ({
|
|||
workflows
|
||||
</p>
|
||||
<div>
|
||||
{templates.map((template) => (
|
||||
{settings.templates.map((template) => (
|
||||
<TemplateItem
|
||||
key={template.id}
|
||||
template={template}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import { TemplateSettings } from "./TemplateSettings";
|
|||
import { BehaviourSettings } from "./BehaviourSettings";
|
||||
import { CustomStatusSettings } from "./CustomStatusSettings";
|
||||
import { QuickCommandsSettings } from "./QuickCommandsSettings";
|
||||
import { PREDEFINED_TEMPLATES } from "@/constants/predefinedTemplates";
|
||||
|
||||
export type Props = {
|
||||
settings: PluginSettings;
|
||||
|
|
@ -26,18 +25,13 @@ const SettingsUI: React.FC<Props> = ({ settings, onChange }) => {
|
|||
|
||||
return (
|
||||
<div className="note-status-settings">
|
||||
<TemplateSettings
|
||||
settings={settings}
|
||||
onChange={handleChange}
|
||||
templates={PREDEFINED_TEMPLATES}
|
||||
/>
|
||||
<TemplateSettings settings={settings} onChange={handleChange} />
|
||||
<UISettings settings={localSettings} onChange={handleChange} />
|
||||
<BehaviourSettings settings={settings} onChange={handleChange} />
|
||||
<CustomStatusSettings settings={settings} onChange={handleChange} />
|
||||
<QuickCommandsSettings
|
||||
settings={settings}
|
||||
onChange={handleChange}
|
||||
templates={PREDEFINED_TEMPLATES}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ export type PluginSettings = {
|
|||
statusColors: Record<string, string>;
|
||||
showStatusBar: boolean;
|
||||
autoHideStatusBar: boolean;
|
||||
templates: StatusTemplate[];
|
||||
customStatuses: NoteStatus[];
|
||||
showStatusIconsInExplorer: boolean;
|
||||
hideUnknownStatusInExplorer: boolean;
|
||||
|
|
|
|||
Loading…
Reference in a new issue