Share schedule-editing and starter-seed-state helpers across platforms
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// StarterSeedState.swift
|
||||
// Workouts
|
||||
//
|
||||
// Copyright 2026 Rouslan Zenetl. All Rights Reserved.
|
||||
//
|
||||
|
||||
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 iOS gallery list, its
|
||||
/// preview screen, and the Mac equivalents so all 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user