add Miniplayer, ActiveWorkoutSession skeleton

This commit is contained in:
Felix Förtsch
2024-09-08 18:34:41 +02:00
parent 03cc854c66
commit f45d6288dd
9 changed files with 357 additions and 41 deletions

View File

@@ -0,0 +1,60 @@
//
// ActiveWorkout.swift
// WorkoutsPlus
//
// Created by Felix Förtsch on 07.09.24.
//
import SwiftUI
struct ActiveWorkoutSession: View {
@Environment(\.dismiss) private var dismiss
@State var workout: Workout
@State var workoutSession: WorkoutSession?
@State var currentExercise: Int = 0
let startDate = Date() - 100
@State private var currentTime = Date()
let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()
var body: some View {
Button("Close") { dismiss() }
Text("\(workout.name)")
Text("Elapsed Time: \(elapsedTimeText(startDate: startDate))")
.onReceive(timer) { time in
currentTime = time // Updates the current time every second
}
List {
// TODO: Unwrap Sets
ForEach(workout.workoutItems) { workoutItem in
HStack {
Text("\(workoutItem.reps)")
Text("\(workoutItem.name)")
}
}
}
.listStyle(.plain)
Image(systemName: "play.circle.fill")
.resizable()
.frame(width: 100, height: 100)
.font(.title)
.symbolRenderingMode(.palette)
.foregroundStyle(.white, .green)
}
private func elapsedTimeText(startDate: Date) -> String {
let elapsedTime = currentTime.timeIntervalSince(startDate)
let formatter = DateComponentsFormatter()
formatter.allowedUnits = [.hour, .minute, .second]
formatter.unitsStyle = .positional // For HH:mm:ss format
return formatter.string(from: elapsedTime) ?? "00:00:00"
}
}
#Preview {
ActiveWorkoutSession(workout: Workout.sampleData)
}