Skip to content

Commit

Permalink
chore: settings store
Browse files Browse the repository at this point in the history
  • Loading branch information
danielo515 committed Dec 19, 2024
1 parent 1a05490 commit a64ae5a
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 57 deletions.
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions src/views/EditFormView.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
106 changes: 54 additions & 52 deletions src/views/ManageFormsView.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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();
}
}

0 comments on commit a64ae5a

Please sign in to comment.