Skip to content

Commit

Permalink
feat(input): document block is async
Browse files Browse the repository at this point in the history
  • Loading branch information
danielo515 committed May 9, 2024
1 parent dae4a25 commit 1e23a1b
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/FormModal.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { App, Modal, Platform, Setting, sanitizeHTMLToDom } from "obsidian";
import { E, absurd, parseFunctionBody, pipe, throttle } from "@std";
import * as R from "fp-ts/Record";
import MultiSelect from "./views/components/MultiSelect.svelte";
import * as TE from "fp-ts/TaskEither";
import { App, Modal, Platform, Setting, sanitizeHTMLToDom } from "obsidian";
import { SvelteComponent } from "svelte";
import { Writable } from "svelte/store";
import FormResult, { type ModalFormData } from "./core/FormResult";
import { formDataFromFormDefaults } from "./core/formDataFromFormDefaults";
import { get_tfiles_from_folder } from "./utils/files";
import type { FormDefinition, FormOptions } from "./core/formDefinition";
import { FieldValue, FormEngine, makeFormEngine } from "./store/formStore";
import { FileSuggest } from "./suggesters/suggestFile";
import { FolderSuggest } from "./suggesters/suggestFolder";
import { DataviewSuggest } from "./suggesters/suggestFromDataview";
import { SvelteComponent } from "svelte";
import { E, parseFunctionBody, pipe, throttle, absurd } from "@std";
import { log_error, log_notice } from "./utils/Log";
import { FieldValue, FormEngine, makeFormEngine } from "./store/formStore";
import { Writable } from "svelte/store";
import { FolderSuggest } from "./suggesters/suggestFolder";
import { get_tfiles_from_folder } from "./utils/files";
import MultiSelect from "./views/components/MultiSelect.svelte";
import { MultiSelectModel, MultiSelectTags } from "./views/components/MultiSelectModel";

export type SubmitFn = (formResult: FormResult) => void;
Expand Down Expand Up @@ -257,21 +258,22 @@ export class FormModal extends Modal {
const sub = this.formEngine.subscribe((form) => {
pipe(
functionParsed,
E.chainW((fn) =>
TE.fromEither,
TE.chainW((fn) =>
pipe(
form.fields,
R.filterMap((field) => field.value),
fn,
),
),
E.match(
TE.match(
(error) => {
console.error(error);
notifyError("Error in document block")(String(error));
},
(newText) => domNode.setText(sanitizeHTMLToDom(newText)),
),
);
)();
});
return this.subscriptions.push(sub);
}
Expand Down

0 comments on commit 1e23a1b

Please sign in to comment.