diff --git a/EXAMPLE_VAULT/.obsidian/plugins/modal-form/data.json b/EXAMPLE_VAULT/.obsidian/plugins/modal-form/data.json index 1b4c3fb..558ab4c 100644 --- a/EXAMPLE_VAULT/.obsidian/plugins/modal-form/data.json +++ b/EXAMPLE_VAULT/.obsidian/plugins/modal-form/data.json @@ -436,6 +436,16 @@ "type": "textarea", "hidden": false } + }, + { + "name": "dateOfBirth", + "label": "", + "description": "", + "isRequired": false, + "input": { + "type": "date", + "hidden": false + } } ], "version": "1", @@ -499,35 +509,35 @@ }, { "_tag": "text", - "value": ");\nconst birthYear = now.year() - age;\n_%>\n\n# " + "value": ");\nconst birthYear = now.year() - age;\nconst dateOfBirth = moment(" }, { "_tag": "variable", - "value": "name" + "value": "dateOfBirth" }, { "_tag": "text", - "value": "'s Profile\n> Created on <% tp.date.now(\"dddd, MMMM Do YYYY\") %> at <% tp.date.now(\"HH:mm\") %>\n\n## Basic Information\n- **Age**: " + "value": ")\n_%>\n\n# " }, { "_tag": "variable", - "value": "age" + "value": "name" }, { "_tag": "text", - "value": " years old *(born around <%* tR + birthYear %>)*\n- **Date of Birth**: " + "value": "'s Profile\n> Created on <% tp.date.now(\"dddd, MMMM Do YYYY\") %> at <% tp.date.now(\"HH:mm\") %>\n\n## Basic Information\n- **Age**: " }, { "_tag": "variable", - "value": "dateOfBirth" + "value": "age" }, { "_tag": "text", - "value": "\n- **Best Time to Contact**: " + "value": " years old *(born around <%* tR += birthYear %>)*\n- **Date of Birth**: " }, { "_tag": "variable", - "value": "timeOfDay" + "value": "dateOfBirth" }, { "_tag": "text", @@ -539,7 +549,7 @@ }, { "_tag": "text", - "value": "\n- **Days until next birthday**: <%* \nif (tp.frontmatter.dateOfBirth) {\n const birthday = moment(tp.frontmatter.dateOfBirth);\n const nextBirthday = moment(birthday).year(now.year());\n if (nextBirthday.isBefore(now)) {\n nextBirthday.add(1, 'year');\n }\n tR + nextBirthday.diff(now, 'days');\n} else {\n tR + \"Unknown\";\n}\n\nconsole.log({ age, birthYear, frontmatter: tp.frontmatter })\n_%> days\n\n## Preferences\n- **Favorite Book**: [[" + "value": "\n- **Days until next birthday**: <%* \nif (dateOfBirth) {\n const nextBirthday = dateOfBirth.year(now.year());\n if (nextBirthday.isBefore(now)) {\n nextBirthday.add(1, 'year');\n }\n tR += nextBirthday.diff(now, 'days');\n} else {\n tR += \"Unknown\";\n}\n\nconsole.log({ age, birthYear, frontmatter: tp.frontmatter, dateOfBirth })\n_%> days\n\n## Preferences\n- **Favorite Book**: [[" }, { "_tag": "variable", @@ -547,7 +557,7 @@ }, { "_tag": "text", - "value": "]]\n<%* if (tp.frontmatter.favorite_book) { %>\n> [!note] Related Books\n> \\`\\`\\`dataview\n> LIST\n> FROM [[" + "value": "]]\n<%* if (tp.frontmatter.favorite_book) { %>\n> [!note] Related Books\n> ```dataview\n> LIST\n> FROM #book\n> WHERE contains(file.outlinks, [[" }, { "_tag": "variable", @@ -555,7 +565,7 @@ }, { "_tag": "text", - "value": "]]-links\n> SORT file.name ASC\n> \\`\\`\\`\n<%* } %>\n\n## Additional Information\n" + "value": "]])\n> SORT file.name ASC\n> ```\n<%* } %>\n\n## Additional Information\n" }, { "_tag": "variable", diff --git a/src/main.ts b/src/main.ts index fdca1b1..4cf9e65 100644 --- a/src/main.ts +++ b/src/main.ts @@ -351,37 +351,42 @@ export default class ModalFormPlugin extends Plugin { noteContent: string, destinationFolder: string, ): TE.TaskEither { - // Use template service instead of directly creating the file + const loop = (noteContent: string): TE.TaskEither => { + // Use template service instead of directly creating the file + return pipe( + this.templateService.createNoteFromTemplate( + noteContent, + destinationFolder, + noteName, + false, // don't open the new note + ), + TE.orElse((error) => { + logger.error(error); + return pipe( + TE.tryCatch( + () => + this.api.openForm(retryForm, { + values: { + title: error.message, + template: noteContent, + }, + }), + E.toError, + ), + TE.map((result) => result.get("template")), + TE.chain((template) => { + if (typeof template !== "string") { + notifyWarning("Failed while retrying")("Template is not a string"); + return TE.left(new Error("Template is not a string")); + } + return loop(template); + }), + ); + }), + ); + }; return pipe( - this.templateService.createNoteFromTemplate( - noteContent, - destinationFolder, - noteName, - false, // don't open the new note - ), - TE.orElse((error) => { - logger.error(error); - return pipe( - TE.tryCatch( - () => - this.api.openForm(retryForm, { - values: { - title: error.message, - template: noteContent, - }, - }), - E.toError, - ), - TE.map((result) => result.get("template")), - TE.chain((template) => { - if (typeof template !== "string") { - notifyWarning("Failed while retrying")("Template is not a string"); - return TE.left(new Error("Template is not a string")); - } - return this.createNoteFromTemplate(noteName, template, destinationFolder); - }), - ); - }), + loop(noteContent), TE.tapIO(() => () => { log_notice( "Note created successfully",