add WorkoutIconSelector to select icon and color for a Workout
This commit is contained in:
@@ -14,8 +14,9 @@ final class Exercise: Nameable {
|
||||
|
||||
var id = UUID()
|
||||
@Attribute(.unique) var name: String
|
||||
// var metric: String = "reps"
|
||||
// var metric: String = "reps"
|
||||
// var exerciseDescription: ExerciseDescription?
|
||||
// var focus: ExerciseFocus? // Strength, Flexibility, Speed, etc
|
||||
|
||||
var timestamp: Date = Date.now
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// Created by Felix Förtsch on 10.08.24.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
import SwiftData
|
||||
|
||||
@Model
|
||||
@@ -15,8 +15,12 @@ final class Workout: Nameable {
|
||||
var id = UUID()
|
||||
@Attribute(.unique) var name: String
|
||||
|
||||
// Icon
|
||||
var workoutIconSystemName = "figure.run.square.stack"
|
||||
var workoutIconColorName = ColorName.black
|
||||
|
||||
// Other properties and methods
|
||||
var timestamp: Date = Date.now
|
||||
var timestamp = Date.now
|
||||
|
||||
@Relationship(deleteRule: .cascade) var workoutItems: [WorkoutItem] = []
|
||||
|
||||
@@ -46,7 +50,64 @@ final class Workout: Nameable {
|
||||
exercise.position = index
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension Workout {
|
||||
// This enum maps the system colors to enable storing them with the SwiftData model data as String.
|
||||
// See Workout.workoutIconColorName for a usage example.
|
||||
// TODO: Use a Macro to reduce this horrible contraption to something maintainable.
|
||||
enum ColorName: String, Codable {
|
||||
case black
|
||||
case blue
|
||||
case cyan
|
||||
case gray
|
||||
case green
|
||||
case indigo
|
||||
case mint
|
||||
case orange
|
||||
case pink
|
||||
case purple
|
||||
case red
|
||||
case white
|
||||
case yellow
|
||||
|
||||
var color: Color {
|
||||
switch self {
|
||||
case .black: return .black
|
||||
case .blue: return .blue
|
||||
case .cyan: return .cyan
|
||||
case .gray: return .gray
|
||||
case .green: return .green
|
||||
case .indigo: return .indigo
|
||||
case .mint: return .mint
|
||||
case .orange: return .orange
|
||||
case .pink: return .pink
|
||||
case .purple: return .purple
|
||||
case .red: return .red
|
||||
case .white: return .white
|
||||
case .yellow: return .yellow
|
||||
}
|
||||
}
|
||||
|
||||
static func fromColor(_ color: Color) -> ColorName? {
|
||||
switch color {
|
||||
case .black: return .black
|
||||
case .blue: return .blue
|
||||
case .cyan: return .cyan
|
||||
case .gray: return .gray
|
||||
case .green: return .green
|
||||
case .indigo: return .indigo
|
||||
case .mint: return .mint
|
||||
case .orange: return .orange
|
||||
case .pink: return .pink
|
||||
case .purple: return .purple
|
||||
case .red: return .red
|
||||
case .white: return .white
|
||||
case .yellow: return .yellow
|
||||
default: return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Workout {
|
||||
|
||||
@@ -22,6 +22,8 @@ final class WorkoutItem: Nameable, Positionable {
|
||||
// EXERCISE
|
||||
var exercise: Exercise?
|
||||
// TODO: Think about what's happening when an exercise (template) is deleted or changed
|
||||
// If it is delete -> we just keep the WorkoutItem with the name :)
|
||||
// The only relevant delete is delete Workout -> Delete Workoutitems
|
||||
// { didSet { self.name = exercise?.name ?? "self.name" } }
|
||||
|
||||
init(_ reps: Int, _ exercise: String) {
|
||||
|
||||
Reference in New Issue
Block a user