From a64ae5adc7445403179e57cb9c443d69164c856b Mon Sep 17 00:00:00 2001 From: Danielo Rodriguez Date: Thu, 19 Dec 2024 11:08:04 +0100 Subject: [PATCH] chore: settings store --- src/main.ts | 2 +- src/store/{store.ts => SettngsStore.ts} | 0 src/views/EditFormView.ts | 8 +- src/views/ManageFormsView.ts | 106 ++++++++++++------------ 4 files changed, 59 insertions(+), 57 deletions(-) rename src/store/{store.ts => SettngsStore.ts} (100%) diff --git a/src/main.ts b/src/main.ts index 4cf9e655..c9e3a059 100644 --- a/src/main.ts +++ b/src/main.ts @@ -23,7 +23,7 @@ import { TemplateService } from "./core/template/TemplateService"; import { getTemplateService } from "./core/template/getTemplateService"; import { retryForm } from "./core/template/retryForm"; import { executeTemplate } from "./core/template/templateParser"; -import { settingsStore } from "./store/store"; +import { settingsStore } from "./store/SettngsStore"; import { FormPickerModal } from "./suggesters/FormPickerModal"; import { NewNoteModal } from "./suggesters/NewNoteModal"; import { log_error, log_notice, notifyWarning } from "./utils/Log"; diff --git a/src/store/store.ts b/src/store/SettngsStore.ts similarity index 100% rename from src/store/store.ts rename to src/store/SettngsStore.ts diff --git a/src/views/EditFormView.ts b/src/views/EditFormView.ts index a62738ba..a680235b 100644 --- a/src/views/EditFormView.ts +++ b/src/views/EditFormView.ts @@ -1,9 +1,9 @@ -import ModalFormPlugin from "../main"; import { ItemView, type ViewStateResult, WorkspaceLeaf } from "obsidian"; -import type { FormDefinition, EditableFormDefinition } from "../core/formDefinition"; -import FormEditor from './FormBuilder.svelte' +import { settingsStore } from "src/store/SettngsStore"; import { log_notice } from "src/utils/Log"; -import { settingsStore } from "src/store/store"; +import type { EditableFormDefinition, FormDefinition } from "../core/formDefinition"; +import ModalFormPlugin from "../main"; +import FormEditor from './FormBuilder.svelte'; export const EDIT_FORM_VIEW = "modal-form-edit-form-view"; diff --git a/src/views/ManageFormsView.ts b/src/views/ManageFormsView.ts index 42b00e49..9071c42e 100644 --- a/src/views/ManageFormsView.ts +++ b/src/views/ManageFormsView.ts @@ -1,6 +1,10 @@ import { ItemView, Notice, WorkspaceLeaf } from "obsidian"; import { FormDefinition } from "src/core/formDefinition"; -import { formsStore, invalidFormsStore, settingsStore } from "src/store/store"; +import { + formsStore, + invalidFormsStore, + settingsStore, +} from "src/store/SettngsStore"; import ModalFormPlugin from "../main"; import ManageForms from "./ManageForms.svelte"; @@ -10,60 +14,58 @@ export const MANAGE_FORMS_VIEW = "modal-form-manage-forms-view"; * Manage existing forms and create new ones */ export class ManageFormsView extends ItemView { - component!: ManageForms; - constructor( - readonly leaf: WorkspaceLeaf, - readonly plugin: ModalFormPlugin, - ) { - super(leaf); - this.icon = "documents"; - } + component!: ManageForms; + constructor(readonly leaf: WorkspaceLeaf, readonly plugin: ModalFormPlugin) { + super(leaf); + this.icon = "documents"; + } - getViewType() { - return MANAGE_FORMS_VIEW; - } + getViewType() { + return MANAGE_FORMS_VIEW; + } - getDisplayText() { - return "Manage forms"; - } + getDisplayText() { + return "Manage forms"; + } - async onOpen() { - // console.log('On open manage forms'); - const container = this.containerEl.children[1] || this.containerEl.createDiv(); - container.empty(); + async onOpen() { + // console.log('On open manage forms'); + const container = + this.containerEl.children[1] || this.containerEl.createDiv(); + container.empty(); - this.component = new ManageForms({ - target: container, - props: { - forms: formsStore, - invalidForms: invalidFormsStore, - createNewForm: () => { - this.plugin.createNewForm(); - }, - editForm: (formName: string) => { - this.plugin.editForm(formName); - }, - deleteForm: (formName: string) => { - settingsStore.removeForm(formName); - }, - duplicateForm: (formName: string) => { - settingsStore.duplicateForm(formName); - }, - copyFormToClipboard: async (form: FormDefinition) => { - await navigator.clipboard.writeText(JSON.stringify(form, null, 2)); - new Notice("Form has been copied to the clipboard"); - }, - openImportFormModal: () => { - this.plugin.openImportFormModal(); - }, - openInTemplateBuilder: (formDefinition: FormDefinition) => { - this.plugin.openTemplateBuilder({ formDefinition }); - }, - }, - }); - } + this.component = new ManageForms({ + target: container, + props: { + forms: formsStore, + invalidForms: invalidFormsStore, + createNewForm: () => { + this.plugin.createNewForm(); + }, + editForm: (formName: string) => { + this.plugin.editForm(formName); + }, + deleteForm: (formName: string) => { + settingsStore.removeForm(formName); + }, + duplicateForm: (formName: string) => { + settingsStore.duplicateForm(formName); + }, + copyFormToClipboard: async (form: FormDefinition) => { + await navigator.clipboard.writeText(JSON.stringify(form, null, 2)); + new Notice("Form has been copied to the clipboard"); + }, + openImportFormModal: () => { + this.plugin.openImportFormModal(); + }, + openInTemplateBuilder: (formDefinition: FormDefinition) => { + this.plugin.openTemplateBuilder({ formDefinition }); + }, + }, + }); + } - async onClose() { - this.component.$destroy(); - } + async onClose() { + this.component.$destroy(); + } }