Add nextDueDate field to TaskResponse for recurring task support

- Add nextDueDate field to TaskResponse model (from API's next_due_date)
- Add effectiveDueDate computed property (nextDueDate ?? dueDate)
- Update DynamicTaskCard, TaskCard to display effectiveDueDate
- Update WidgetDataManager to save effectiveDueDate to widget cache
- Update TaskFormView to use effectiveDueDate when editing
- Fix preview mock data to include nextDueDate parameter

This ensures recurring tasks show the correct next due date after completion
instead of the original due date.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Trey t
2025-12-11 11:10:56 -06:00
parent cbe073aa21
commit 1839bd0e11
6 changed files with 15 additions and 8 deletions

View File

@@ -44,6 +44,7 @@ data class TaskResponse(
@SerialName("frequency_id") val frequencyId: Int? = null,
val frequency: TaskFrequency? = null,
@SerialName("due_date") val dueDate: String? = null,
@SerialName("next_due_date") val nextDueDate: String? = null, // For recurring tasks, updated after each completion
@SerialName("estimated_cost") val estimatedCost: Double? = null,
@SerialName("actual_cost") val actualCost: Double? = null,
@SerialName("contractor_id") val contractorId: Int? = null,
@@ -74,8 +75,11 @@ data class TaskResponse(
val priorityName: String? get() = priority?.name
val priorityDisplayName: String? get() = priority?.displayName
// Effective due date: use nextDueDate if set (for recurring tasks), otherwise use dueDate
val effectiveDueDate: String? get() = nextDueDate ?: dueDate
// Fields that don't exist in Go API - return null/default
val nextScheduledDate: String? get() = null // Would need calculation based on frequency
val nextScheduledDate: String? get() = nextDueDate // Now we have this from the API
val showCompletedButton: Boolean get() = true // Always show complete button since status is now just in_progress boolean
val daySpan: Int? get() = frequency?.days
val notifyDays: Int? get() = null // Not in Go API

View File

@@ -275,7 +275,7 @@ final class WidgetDataManager {
description: task.description_,
priority: task.priority?.name ?? "",
inProgress: task.inProgress,
dueDate: task.dueDate,
dueDate: task.effectiveDueDate, // Use effective date (nextDueDate if set, otherwise dueDate)
category: task.category?.name ?? "",
residenceName: "", // No longer available in API, residence lookup needed
isOverdue: column.name == "overdue_tasks"

View File

@@ -49,8 +49,8 @@ struct DynamicTaskCard: View {
Spacer()
if let due_date = task.dueDate {
Label(DateUtils.formatDate(due_date), systemImage: "calendar")
if let effectiveDate = task.effectiveDueDate {
Label(DateUtils.formatDate(effectiveDate), systemImage: "calendar")
.font(.caption)
.foregroundColor(Color.appTextSecondary)
}

View File

@@ -58,12 +58,12 @@ struct TaskCard: View {
Spacer()
if let dueDate = task.dueDate {
if let effectiveDate = task.effectiveDueDate {
HStack(spacing: AppSpacing.xxs) {
Image(systemName: "calendar")
.font(.system(size: 12, weight: .medium))
.foregroundColor(Color.appTextSecondary.opacity(0.7))
Text(DateUtils.formatDate(dueDate))
Text(DateUtils.formatDate(effectiveDate))
.font(.caption.weight(.medium))
.foregroundColor(Color.appTextSecondary)
}
@@ -262,6 +262,7 @@ struct TaskCard: View {
frequencyId: 1,
frequency: TaskFrequency(id: 1, name: "monthly", days: 30, displayOrder: 0),
dueDate: "2024-12-15",
nextDueDate: nil,
estimatedCost: 150.00,
actualCost: nil,
contractorId: nil,

View File

@@ -96,6 +96,7 @@ struct TasksSection: View {
frequencyId: 1,
frequency: TaskFrequency(id: 1, name: "monthly", days: 30, displayOrder: 0),
dueDate: "2024-12-15",
nextDueDate: nil,
estimatedCost: 150.00,
actualCost: nil,
contractorId: nil,
@@ -135,6 +136,7 @@ struct TasksSection: View {
frequencyId: 6,
frequency: TaskFrequency(id: 6, name: "once", days: nil, displayOrder: 0),
dueDate: "2024-11-01",
nextDueDate: nil,
estimatedCost: 200.00,
actualCost: nil,
contractorId: nil,

View File

@@ -66,10 +66,10 @@ struct TaskFormView: View {
_selectedPriority = State(initialValue: task.priority)
_inProgress = State(initialValue: task.inProgress)
// Parse date from string
// Parse date from string - use effective due date (nextDueDate if set, otherwise dueDate)
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd"
_dueDate = State(initialValue: formatter.date(from: task.dueDate ?? "") ?? Date())
_dueDate = State(initialValue: formatter.date(from: task.effectiveDueDate ?? "") ?? Date())
_intervalDays = State(initialValue: "") // No longer in API
_estimatedCost = State(initialValue: task.estimatedCost != nil ? String(task.estimatedCost!.doubleValue) : "")