Queue document writes durably and surface sync trouble in the UI

iCloud Drive writes now flow through a persistent WriteBacklog sidecar
(drained with backoff, flushed on backgrounding, wiped with the cache on
account change), so a save can never be lost to a transient coordinator
error. A status banner on the workout list surfaces stuck syncing.
Also: the split picker gains a Recent section with day labels, split
rows fold SplitItem into SplitListView, and list rows dim the multiply
sign in sets-by-reps.

Claude-Session: https://claude.ai/code/session_01HJDQQDA9QdP8zByg43H5v3
This commit is contained in:
2026-07-08 12:48:12 -04:00
parent 495fce1e5a
commit c05e83cff7
13 changed files with 1175 additions and 144 deletions
@@ -18,6 +18,14 @@ enum WorkoutsModelContainer {
URL.applicationSupportDirectory.appending(path: "Workouts.store")
}
/// Sidecar file holding queued-but-unwritten document writes (`WriteBacklog`,
/// iOS only). Lives beside the cache store outside the iCloud container
/// and is wiped with it on an account change: a backlog from one account must
/// never drain into another account's container.
static var pendingWritesURL: URL {
URL.applicationSupportDirectory.appending(path: "PendingWrites.json")
}
static func make() -> ModelContainer {
let schema = Schema([Split.self, Exercise.self, Workout.self, WorkoutLog.self])
ensureStoreDirectoryExists()
@@ -70,6 +78,7 @@ enum WorkoutsModelContainer {
let stored = UserDefaults.standard.data(forKey: identityTokenKey)
guard current != stored else { return }
wipeStore()
try? FileManager.default.removeItem(at: pendingWritesURL)
UserDefaults.standard.set(current, forKey: identityTokenKey)
}