Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add implementation to work with reminders in Full Note Events #366 #463

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/calendars/FullNoteCalendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@ function newFrontmatter(fields: Partial<OFCEvent>): string {
);
}

function createReminder(fields: Partial<OFCEvent>): string {
const type = Object.entries(fields).filter(([k, _]) => k === "type");
if (type[0][1] === "recurring") return "";
const dateField = Object.entries(fields).filter(([k, _]) => k === "date");
const date = dateField[0][1] ?? "no date";
const startField = Object.entries(fields).filter(
([k, _]) => k === "startTime"
);
const startTime = startField[0][1] ?? "no startTime";
return `- [ ] Reminder for this event (@${date} ${startTime})`;
}

function modifyFrontmatterString(
page: string,
modifications: Partial<OFCEvent>
Expand Down Expand Up @@ -140,6 +152,19 @@ function modifyFrontmatterString(
)
);
}
console.log(newFrontmatter);
const pairs: { [name: string]: string } = { abc: "abc" };
newFrontmatter.forEach((item) => {
const [key, ...values] = item.split(":").map((entry) => entry.trim());
pairs[key] = values.join(":");
});
console.log(pairs);
const date: string = pairs["date"] || "no date";
const startTime: string = pairs["startTime"] || "no startTime";

console.log(page);
page = page.replace(/\(@([^]+)\)/, `(@${date} ${startTime})`);
console.log(page);
return replaceFrontmatter(page, newFrontmatter.join("\n") + "\n");
}

Expand Down Expand Up @@ -220,7 +245,10 @@ export default class FullNoteCalendar extends EditableCalendar {
if (this.app.getAbstractFileByPath(path)) {
throw new Error(`Event at ${path} already exists.`);
}
const file = await this.app.create(path, newFrontmatter(event));
const file = await this.app.create(
path,
newFrontmatter(event) + createReminder(event)
);
return { file, lineNumber: undefined };
}

Expand Down