Skip to content

Commit

Permalink
fix: button to open import modal from form manager
Browse files Browse the repository at this point in the history
  • Loading branch information
danielo515 committed Jan 21, 2024
1 parent 024b513 commit 1cc834e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
22 changes: 12 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function notifyParsingErrors(errors: InvalidData[]) {
return;
}
log_notice(
"Some forms could not be parsed",
"⚠️ Some forms could not be parsed ⚠️",
`We found some invalid data while parsing the form settings, please take a look at the following errors:
${errors.join("\n")}`,
);
Expand Down Expand Up @@ -94,6 +94,16 @@ export default class ModalFormPlugin extends Plugin {
await this.activateView(EDIT_FORM_VIEW, formDefinition);
}

openImportFormModal() {
const importModal = new FormImportModal(this.app, {
createForm: (form) => {
importModal.close();
this.activateView(EDIT_FORM_VIEW, form);
},
});
importModal.open();
}

closeEditForm() {
this.app.workspace.detachLeavesOfType(EDIT_FORM_VIEW);
}
Expand Down Expand Up @@ -245,15 +255,7 @@ export default class ModalFormPlugin extends Plugin {
this.addCommand({
id: "import-form",
name: "Import form",
callback: () => {
const importModal = new FormImportModal(this.app, {
createForm: (form) => {
importModal.close();
this.activateView(EDIT_FORM_VIEW, form);
},
});
importModal.open();
},
callback: () => this.openImportFormModal,
});

// This adds a settings tab so the user can configure various aspects of the plugin
Expand Down
6 changes: 5 additions & 1 deletion src/views/ManageForms.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
export let duplicateForm: (formName: string) => void;
export let editForm: (formName: string) => void;
export let copyFormToClipboard: (form: FormDefinition) => void;
export let openImportFormModal: () => void;
export let forms: Readable<FormDefinition[]>;
export let invalidForms: Readable<MigrationError[]>;
Expand All @@ -37,7 +38,10 @@

<div class="header">
<h1>Manage forms</h1>
<Button onClick={createNewForm} text="Create new form" variant="primary"></Button>
<div class="flex gap-1">
<Button onClick={createNewForm} text="Create new form" variant="primary"></Button>
<Button onClick={openImportFormModal} text="Import form" variant="regular"></Button>
</div>
{#if $invalidForms.length}
<h5 class="modal-form-danger">
There are {$invalidForms.length} invalid forms.
Expand Down
23 changes: 12 additions & 11 deletions src/views/ManageFormsView.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { FormDefinition } from "src/core/formDefinition";
import ManageForms from './ManageForms.svelte';
import ManageForms from "./ManageForms.svelte";
import ModalFormPlugin from "../main";
import { ItemView, Notice, WorkspaceLeaf } from "obsidian";
import { formsStore, invalidFormsStore, settingsStore } from "src/store/store";

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) {
constructor(
readonly leaf: WorkspaceLeaf,
readonly plugin: ModalFormPlugin,
) {
super(leaf);
this.icon = "documents";
}
Expand Down Expand Up @@ -42,24 +44,23 @@ export class ManageFormsView extends ItemView {
this.plugin.editForm(formName);
},
deleteForm: (formName: string) => {
settingsStore.removeForm(formName)
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();
},
},
});
}

async onClose() {
this.component.$destroy();
}

}


0 comments on commit 1cc834e

Please sign in to comment.