import type { ReadOnlyReference } from "model/ref" ; import type { Time } from "model/time" ; import { ItemView , View , Workspace , WorkspaceLeaf } from "obsidian" ; import { VIEW_TYPE_REMINDER_LIST } from "../constants" ; import { groupReminders , Reminder , Reminders } from "../model/reminder" ; import ReminderListView from "./components/ReminderList.svelte" ; class ReminderListItemView extends ItemView { private view ? : ReminderListView ; constructor ( leaf , private reminders , private reminderTime , private onOpenReminder ) { super ( leaf ) ; } getViewType ( ) { return VIEW_TYPE_REMINDER_LIST ; } getDisplayText ( ) { return "Reminders" ; } override getIcon ( ) { return "clock" ; } override async onOpen ( ) { this . view = new ReminderListView ( { target : ( this as any ) . contentEl , props : { groups : this . remindersForView ( ) , onOpenReminder : this . onOpenReminder , component : this , } , } ) ; } reload ( ) { if ( this . view == null ) { return ; } this . view . $set ( { groups : this . remindersForView ( ) , onOpenReminder : this . onOpenReminder , } ) ; } private remindersForView ( ) { return groupReminders ( this . reminders . reminders , this . reminderTime . value ) ; } override onClose ( ) { if ( this . view ) { this . view . $destroy ( ) ; } return Promise . resolve ( ) ; } } export class ReminderListItemViewProxy { private valid : boolean = false ; constructor ( private workspace , private reminders , private reminderTime , private onOpenReminder ) { } createView ( leaf ) { return new ReminderListItemView ( leaf , this . reminders , this . reminderTime , this . onOpenReminder ) ; } openView ( ) { if ( this . workspace . getLeavesOfType ( VIEW_TYPE_REMINDER_LIST ) . length ) { return ; } this . workspace . getRightLeaf ( false ) . setViewState ( { type : VIEW_TYPE_REMINDER_LIST , } ) ; } reload ( force = false ) { if ( force || ! this . valid ) { const views = this . getViews ( ) ; if ( views . length > 0 ) { views . forEach ( view => view . reload ( ) ) ; this . valid = true ; } else { this . valid = false ; console . debug ( "view is null.  Skipping reminder list view reload" ) ; } } } private getViews ( ) { return this . workspace . getLeavesOfType ( VIEW_TYPE_REMINDER_LIST ) . map ( leaf => leaf . view as ReminderListItemView ) ; } invalidate ( ) { this . valid = false ; } }