fix: migrate persisted gamified emojis on load

UserDefaults retained the old 🔥/💥 emojis from before the sample data
was cleaned. On init, replace those emojis in loaded programs and persist
the result so they don't reappear after restart.
This commit is contained in:
kutesir
2026-05-27 23:55:38 +03:00
parent 36191f616f
commit e105af147d

View File

@@ -190,7 +190,13 @@ class WorkoutViewModel: ObservableObject {
let saved = try? JSONDecoder().decode([WorkoutProgram].self, from: data),
!saved.isEmpty {
programs = saved
let gamifiedEmojis: Set<String> = ["🔥", "💥"]
let emojiMap = ["🔥": "🔄", "💥": "🏋️"]
let needsMigration = saved.contains(where: { gamifiedEmojis.contains($0.emoji) })
programs = needsMigration ? saved.map { p in
guard let replacement = emojiMap[p.emoji] else { return p }
var copy = p; copy.emoji = replacement; return copy
} : saved
var sched: [Int: UUID] = [:]
if let dict = UserDefaults.standard.dictionary(forKey: Self.kSchedule) as? [String: String] {
@@ -205,7 +211,9 @@ class WorkoutViewModel: ObservableObject {
let uid = UUID(uuidString: str),
saved.contains(where: { $0.id == uid }) { pid = uid }
activeProgramId = pid
activeSections = saved.first { $0.id == pid }?.sections ?? saved[0].sections
activeSections = programs.first { $0.id == pid }?.sections ?? programs[0].sections
if needsMigration { save() }
} else {
// First launch: seed with sample programs