This commit is contained in:
Trey t
2023-06-25 10:59:20 -05:00
parent 01915752b6
commit 24ee992f93
14 changed files with 448 additions and 727 deletions

View File

@@ -46,14 +46,22 @@ struct AllWorkoutsView: View {
}
}.onAppear{
if needsUpdating {
AllWorkoutFetchable().fetch(completion: { result in
needsUpdating = false
switch result {
case .success(let model):
DispatchQueue.main.async {
self.workouts = model
}
case .failure(let failure):
UserStore.shared.login(completion: { success in
if success {
DataStore.shared.fetchAllData()
AllWorkoutFetchable().fetch(completion: { result in
needsUpdating = false
switch result {
case .success(let model):
DispatchQueue.main.async {
self.workouts = model
}
case .failure(let failure):
fatalError("shit broke")
}
})
} else {
fatalError("shit broke")
}
})

View File

@@ -21,18 +21,31 @@ struct CompletedWorkoutView: View {
VStack {
topViews()
calsBurned()
heartRates()
rateWorkout()
Divider()
HStack {
calsBurned()
.frame(maxWidth: .infinity)
heartRates()
.frame(maxWidth: .infinity)
}
rateWorkout()
.frame(maxHeight: 88)
Divider()
TextField("Notes", text: $notes)
.frame(height: 55)
.textFieldStyle(PlainTextFieldStyle())
.padding([.horizontal], 4)
.overlay(RoundedRectangle(cornerRadius: 16).stroke(Color(uiColor: .clear))).background(Color(uiColor: .init(red: 200/255, green: 200/255, blue: 200/255, alpha: 0.2)))
.cornerRadius(8)
Spacer()
Button("Upload", action: {
upload(postBody: postData)
})
@@ -66,9 +79,16 @@ struct CompletedWorkoutView: View {
func calsBurned() -> some View {
VStack {
Divider()
Text("calroies burned")
Text("\(postData["total_calories"] as! Float)")
if let cals = postData["total_calories"] as? Float {
HStack {
Image(systemName: "flame.fill")
.foregroundColor(.orange)
.font(.title)
VStack {
Text("\(cals, specifier: "%.0f")")
}
}
}
}
}
@@ -76,24 +96,47 @@ struct CompletedWorkoutView: View {
VStack {
Divider()
Text("how hard was this shit")
HStack {
Text("easy")
Text("Easy")
.foregroundColor(.green)
Spacer()
Text("Death")
.foregroundColor(.red)
}
Slider(value: $difficulty, in: 0...5, step: 1)
ZStack {
LinearGradient(
gradient: Gradient(colors: [.green, .red]),
startPoint: .leading,
endPoint: .trailing
)
.mask(Slider(value: $difficulty, in: 0...5, step: 1))
// Dummy replicated slider, to allow sliding
Slider(value: $difficulty, in: 0...5, step: 1)
.opacity(0.05) // Opacity is the trick here.
.accentColor(.clear)
}
}
}
func heartRates() -> some View {
VStack {
Divider()
if let heartRates = postData["heart_rates"] as? [Int] {
let avg = heartRates.reduce(0, +)/heartRates.count
Text("Avg heart rate: \(avg)")
HStack {
Image(systemName: "heart")
.foregroundColor(.red)
.font(.title)
VStack {
HStack {
Text("\(heartRates.min() ?? 0)")
Text("-")
Text("\(heartRates.max() ?? 0)")
}
Text("\(avg)")
}
}
}
}
}
@@ -119,17 +162,21 @@ struct CompletedWorkoutView: View {
}
}
//struct CompletedWorkoutView_Previews: PreviewProvider {
// static let postBody = [
// "difficulty": 1,
// "workout_start_time": Date().timeFormatForUpload,
// "workout": 1,
// "total_time": 140
// ] as [String : Any]
//
// static let workout = PreviewWorkout.workout()
//
// static var previews: some View {
// CompletedWorkoutView(postData: CompletedWorkoutView_Previews.postBody, workout: workout)
// }
//}
struct CompletedWorkoutView_Previews: PreviewProvider {
static let postBody = [
"difficulty": 1,
"workout_start_time": Date().timeFormatForUpload,
"workout": 1,
"total_time": 140,
"total_calories": Float(120.0),
"heart_rates": [65,65,4,54,232,12]
] as [String : Any]
static let workout = PreviewWorkout.workout()
static var previews: some View {
CompletedWorkoutView(postData: CompletedWorkoutView_Previews.postBody,
workout: workout,
completedWorkoutDismissed: { _ in })
}
}