Add task priority (High/Medium/Low/None) with colored flag picker

Priority stored on TaskItem, shown as colored flag in add sheet toolbar
and as a small flag indicator on each task row.

Co-Authored-By: Kutesir <tqwyy79vzn@privaterelay.appleid.com>
This commit is contained in:
Robin Kutesa
2026-06-01 03:57:48 +03:00
parent 0483bc04ea
commit 8f041c69f3
2 changed files with 51 additions and 8 deletions

View File

@@ -15,6 +15,33 @@ struct TaskItem: Identifiable, Codable, Equatable {
var isPinned: Bool = false
var endDate: Date? = nil
var isAllDay: Bool = false
var priority: Priority = .none
}
enum Priority: String, Codable, CaseIterable, Identifiable {
var id: String { rawValue }
case high = "High"
case medium = "Medium"
case low = "Low"
case none = "None"
var color: Color {
switch self {
case .high: return .red
case .medium: return .yellow
case .low: return .blue
case .none: return Color(.systemGray3)
}
}
var label: String {
switch self {
case .high: return "High Priority"
case .medium: return "Medium Priority"
case .low: return "Low Priority"
case .none: return "No Priority"
}
}
}
enum Quadrant: String, CaseIterable, Identifiable, Codable {
@@ -162,11 +189,13 @@ class TaskViewModel: ObservableObject {
func addTask(title: String, dueDate: Date?, hasTime: Bool = false,
quadrant: Quadrant = .urgent, category: TaskCategory = .reminder,
taskColor: TaskColor = .orange, isRecurring: Bool = false,
endDate: Date? = nil, isAllDay: Bool = false) {
endDate: Date? = nil, isAllDay: Bool = false,
priority: Priority = .none) {
tasks.append(TaskItem(title: title, dueDate: dueDate, hasTime: hasTime,
quadrant: quadrant, category: category,
taskColor: taskColor, isRecurring: isRecurring,
endDate: endDate, isAllDay: isAllDay))
endDate: endDate, isAllDay: isAllDay,
priority: priority))
save()
}