import { MarkdownDocument , modifyReminder , parseReminder , ReminderEdit } from "model/format" ; import type { Reminder } from "model/reminder" ; import type { Todo } from "./format/markdown" ; export type ReminderTodoEdit = ReminderEdit & { checked ? : boolean ; } ; export class Content { private doc : MarkdownDocument ; constructor ( file , content ) { this . doc = new MarkdownDocument ( file , content ) ; } public getReminders ( doneOnly = true ) { const reminders = parseReminder ( this . doc ) ; if ( ! doneOnly ) { return reminders ; } return reminders . filter ( reminder => ! reminder . done ) ; } public getTodos ( ) { return this . doc . getTodos ( ) ; } public async modifyReminderLines ( modifyFunc ) { for ( const reminder of this . getReminders ( false ) ) { const edit = modifyFunc ( reminder ) ; if ( edit === null ) { return ; } await this . modifyReminderLine ( reminder , edit ) ; } } public async updateReminder ( reminder , edit ) { await this . modifyReminderLine ( reminder , edit ) ; } private async modifyReminderLine ( reminder , edit ) { const modified = await modifyReminder ( this . doc , reminder , edit ) ; if ( modified ) { console . info ( "Reminder was updated: reminder=%o" , reminder ) ; } else { console . warn ( "Cannot modify reminder because it's not a reminder todo: reminder=%o" , reminder ) ; } return modified ; } public getContent ( ) { return this . doc . toMarkdown ( ) ; } }