()
| 68 | } |
| 69 | |
| 70 | private async initializeWithFreshData(): Promise<void> { |
| 71 | const { contentEl } = this; |
| 72 | |
| 73 | // Fetch fresh task data to avoid working with stale data |
| 74 | if (this.task.path && this.task.path.trim() !== "") { |
| 75 | const freshTask = await this.plugin.cacheManager.getTaskInfo(this.task.path); |
| 76 | if (freshTask) { |
| 77 | this.task = freshTask; |
| 78 | this.reminders = freshTask.reminders ? [...freshTask.reminders] : []; |
| 79 | this.originalReminders = freshTask.reminders ? [...freshTask.reminders] : []; |
| 80 | } else { |
| 81 | // Task path exists but not found in cache - use provided task data |
| 82 | // This can happen during edit when changes haven't been saved yet |
| 83 | this.reminders = this.task.reminders ? [...this.task.reminders] : []; |
| 84 | this.originalReminders = this.task.reminders ? [...this.task.reminders] : []; |
| 85 | } |
| 86 | } else { |
| 87 | // Task doesn't have a path yet (new task being created) |
| 88 | // Use the provided task data |
| 89 | this.reminders = this.task.reminders ? [...this.task.reminders] : []; |
| 90 | this.originalReminders = this.task.reminders ? [...this.task.reminders] : []; |
| 91 | } |
| 92 | |
| 93 | // Clear loading state and render the actual modal content |
| 94 | contentEl.empty(); |
| 95 | contentEl.addClass("tasknotes-plugin"); |
| 96 | contentEl.addClass("tasknotes-reminder-modal"); |
| 97 | |
| 98 | // Compact header |
| 99 | const headerContainer = contentEl.createDiv({ cls: "reminder-modal__header" }); |
| 100 | headerContainer.createEl("h2", { text: "Task reminders" }); |
| 101 | |
| 102 | headerContainer.createDiv({ |
| 103 | cls: "reminder-modal__task-title", |
| 104 | text: this.task.title, |
| 105 | }); |
| 106 | |
| 107 | // Add task dates context if available |
| 108 | const contextInfo = this.getTaskContextInfo(); |
| 109 | if (contextInfo) { |
| 110 | const taskDates = headerContainer.createDiv({ cls: "reminder-modal__task-dates" }); |
| 111 | taskDates.textContent = contextInfo; |
| 112 | } |
| 113 | |
| 114 | // Main content area - more compact |
| 115 | const contentContainer = contentEl.createDiv({ cls: "reminder-modal__content" }); |
| 116 | |
| 117 | // Existing reminders section |
| 118 | this.renderExistingReminders(contentContainer); |
| 119 | |
| 120 | // Add new reminder section |
| 121 | this.renderAddReminderForm(contentContainer); |
| 122 | |
| 123 | // Action buttons |
| 124 | this.renderActionButtons(contentEl); |
| 125 | |
| 126 | // Set up keyboard handlers and update save button state |
| 127 | this.setupKeyboardHandlers(); |
no test coverage detected