initial pre-viable version of watch app
This commit is contained in:
117
Worksouts Watch App/Views/WorkoutLogListView.swift
Normal file
117
Worksouts Watch App/Views/WorkoutLogListView.swift
Normal file
@ -0,0 +1,117 @@
|
||||
import SwiftUI
|
||||
import SwiftData
|
||||
|
||||
struct WorkoutLogListView: View {
|
||||
@Environment(\.modelContext) private var modelContext
|
||||
let workout: Workout
|
||||
|
||||
@State private var selectedLogIndex: Int = 0
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
if let logs = workout.logs?.sorted(by: { $0.order < $1.order }), !logs.isEmpty {
|
||||
TabView(selection: $selectedLogIndex) {
|
||||
ForEach(Array(logs.enumerated()), id: \.element.id) { index, log in
|
||||
WorkoutLogCard(log: log, index: index)
|
||||
.tag(index)
|
||||
}
|
||||
}
|
||||
.tabViewStyle(.page)
|
||||
// .indexViewStyle(.page(backgroundDisplayMode: .always))
|
||||
} else {
|
||||
Text("No exercises in this workout")
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
}
|
||||
.navigationTitle(workout.split?.name ?? "Workout")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
}
|
||||
}
|
||||
|
||||
struct WorkoutLogCard: View {
|
||||
let log: WorkoutLog
|
||||
let index: Int
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 12) {
|
||||
Text(log.exerciseName)
|
||||
.font(.headline)
|
||||
.multilineTextAlignment(.center)
|
||||
|
||||
HStack {
|
||||
VStack {
|
||||
Text("\(log.sets)")
|
||||
.font(.title2)
|
||||
Text("Sets")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
|
||||
VStack {
|
||||
Text("\(log.reps)")
|
||||
.font(.title2)
|
||||
Text("Reps")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
|
||||
VStack {
|
||||
Text("\(log.weight)")
|
||||
.font(.title2)
|
||||
Text("Weight")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.secondary)
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
}
|
||||
|
||||
NavigationLink {
|
||||
ExerciseProgressView(log: log)
|
||||
} label: {
|
||||
Text("Start")
|
||||
.font(.headline)
|
||||
.foregroundStyle(.white)
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, 8)
|
||||
.background(Color.blue)
|
||||
.cornerRadius(8)
|
||||
}
|
||||
.buttonStyle(PlainButtonStyle())
|
||||
|
||||
Text(log.status?.name ?? "Not Started")
|
||||
.font(.caption)
|
||||
.foregroundStyle(statusColor(for: log.status))
|
||||
}
|
||||
.padding()
|
||||
.background(Color.secondary.opacity(0.2))
|
||||
.cornerRadius(12)
|
||||
.padding(.horizontal)
|
||||
}
|
||||
|
||||
private func statusColor(for status: WorkoutStatus?) -> Color {
|
||||
guard let status = status else { return .secondary }
|
||||
|
||||
switch status {
|
||||
case .notStarted:
|
||||
return .secondary
|
||||
case .inProgress:
|
||||
return .blue
|
||||
case .completed:
|
||||
return .green
|
||||
case .skipped:
|
||||
return .red
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
let container = AppContainer.preview
|
||||
let workout = Workout(start: Date(), end: Date(), split: nil)
|
||||
let log1 = WorkoutLog(workout: workout, exerciseName: "Bench Press", date: Date(), sets: 3, reps: 10, weight: 135)
|
||||
let log2 = WorkoutLog(workout: workout, exerciseName: "Squats", date: Date(), order: 1, sets: 3, reps: 8, weight: 225)
|
||||
|
||||
return WorkoutLogListView(workout: workout)
|
||||
.modelContainer(container)
|
||||
}
|
Reference in New Issue
Block a user