Matrix: backfill legacy task priorities so birthdays place correctly (KC-21)

The Priority defaults only fired at creation, so tasks saved before Priority
existed (e.g. birthdays) all had `.none` and fell to the Matrix bottom row
instead of Q2. Added a one-time, flag-guarded migration on load that applies
the KisaniCal category defaults (birthday/domain/annual/exam/subscription →
High, workout → Medium) to existing `.none`-priority tasks.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
kutesir
2026-06-15 12:59:48 +03:00
parent 3592d2a9d8
commit fae56cb2a8

View File

@@ -152,6 +152,22 @@ class TaskViewModel: ObservableObject {
} else { } else {
tasks = [] tasks = []
} }
migrateCategoryPrioritiesIfNeeded()
}
/// One-time backfill: tasks created before Priority existed all have `.none`.
/// Apply the KisaniCal category defaults (birthdays High, etc.) so the Matrix
/// places legacy birthdays/renewals in the top row like newly-created ones.
private func migrateCategoryPrioritiesIfNeeded() {
let flag = "kisani.migration.categoryPriority.v1"
guard !UserDefaults.kisani.bool(forKey: flag) else { return }
var changed = false
for idx in tasks.indices where tasks[idx].priority == .none {
let def = defaultPriority(category: tasks[idx].category, title: tasks[idx].title)
if def != .none { tasks[idx].priority = def; changed = true }
}
UserDefaults.kisani.set(true, forKey: flag)
if changed { save() }
} }
func reload() { func reload() {