Share schedule-editing and starter-seed-state helpers across platforms

This commit is contained in:
2026-07-16 19:54:57 -04:00
parent 9968cb2056
commit f6c5bc911f
4 changed files with 79 additions and 57 deletions
@@ -8,31 +8,6 @@
import SwiftUI
import SwiftData
/// Where a bundled seed currently stands relative to the live cache computed fresh
/// from `@Query` routines on every render so a local edit, a remote change, or a
/// fork-on-edit clone is reflected immediately. Shared by the gallery list and the
/// preview screen so both classify a seed identically.
enum StarterSeedState {
/// A live routine with the seed's fixed id exists the starter is already in the
/// user's library (possibly since edited elsewhere; the id itself only forks at
/// edit time, so "added" still matches a pristine seed).
case added(Routine)
/// Not added, but some *other* live routine already carries the seed's name
/// restoring would read as a confusing duplicate, so the add action is blocked.
case nameTaken
/// Neither added nor blocked free to restore.
case restorable
}
extension SeedLibrary.Seed {
/// Classify this seed against the live routine set. See `StarterSeedState`.
func state(among routines: [Routine]) -> StarterSeedState {
if let live = routines.first(where: { $0.id == id }) { return .added(live) }
if routines.contains(where: { $0.name == doc.name }) { return .nameTaken }
return .restorable
}
}
/// Every bundled starter routine including ones the user has deleted with a
/// per-seed Add/Restore action and a bulk "re-add everything missing" fallback. Unlike
/// `RoutinesLibraryView` (which only ever shows *live* routines), this reads straight