WIP
This commit is contained in:
@@ -9,10 +9,27 @@ import Foundation
|
||||
import SwiftUI
|
||||
|
||||
struct AllWorkoutsView: View {
|
||||
enum MainViews: Int, CaseIterable {
|
||||
case AllWorkout = 0
|
||||
case MyWorkouts
|
||||
|
||||
var title: String {
|
||||
switch self {
|
||||
|
||||
case .AllWorkout:
|
||||
return "All Workouts"
|
||||
case .MyWorkouts:
|
||||
return "Planned Workouts"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@State var workouts: [Workout]?
|
||||
var bridgeModule = BridgeModule.shared
|
||||
@State public var needsUpdating: Bool = true
|
||||
|
||||
@ObservedObject var dataStore = DataStore.shared
|
||||
|
||||
@State private var showWorkoutDetail = false
|
||||
@State private var selectedWorkout: Workout? {
|
||||
didSet {
|
||||
@@ -22,27 +39,32 @@ struct AllWorkoutsView: View {
|
||||
}
|
||||
|
||||
@State private var showLoginView = false
|
||||
@State private var selectedSegment: MainViews = .AllWorkout
|
||||
@State var selectedDate: Date = Date()
|
||||
|
||||
let pub = NotificationCenter.default.publisher(for: NSNotification.Name("CreatedNewWorkout"))
|
||||
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
if let workouts = workouts,
|
||||
let _ = DataStore.shared.allExercise,
|
||||
let _ = DataStore.shared.allMuscles,
|
||||
let _ = DataStore.shared.allEquipment {
|
||||
List {
|
||||
ForEach(workouts, id:\.name) { workout in
|
||||
VStack {
|
||||
Text(workout.name)
|
||||
.font(.title2)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
Text(workout.description ?? "")
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
if let workouts = workouts {
|
||||
if dataStore.status == .loading {
|
||||
ProgressView()
|
||||
.progressViewStyle(.circular)
|
||||
} else {
|
||||
VStack {
|
||||
Picker("", selection: $selectedSegment) {
|
||||
ForEach(MainViews.allCases, id: \.self) { viewType in
|
||||
Text(viewType.title)
|
||||
}
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
selectedWorkout = workout
|
||||
.pickerStyle(.segmented)
|
||||
.padding()
|
||||
|
||||
switch selectedSegment {
|
||||
case .AllWorkout:
|
||||
allWorkoutView(workouts: workouts)
|
||||
case .MyWorkouts:
|
||||
plannedWorkout(workouts: UserStore.shared.plannedWorkouts)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,6 +73,7 @@ struct AllWorkoutsView: View {
|
||||
.progressViewStyle(.circular)
|
||||
}
|
||||
}.onAppear{
|
||||
// UserStore.shared.logout()
|
||||
maybeUpdateShit()
|
||||
}
|
||||
.sheet(item: $selectedWorkout) { item in
|
||||
@@ -69,10 +92,70 @@ struct AllWorkoutsView: View {
|
||||
}
|
||||
}
|
||||
|
||||
func allWorkoutView(workouts: [Workout]) -> some View {
|
||||
List {
|
||||
ForEach(workouts, id:\.name) { workout in
|
||||
VStack {
|
||||
Text(workout.name)
|
||||
.font(.title2)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
Text(workout.description ?? "")
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
selectedWorkout = workout
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func plannedWorkout(workouts: [PlannedWorkout]) -> some View {
|
||||
List {
|
||||
ForEach(workouts, id:\.workout.name) { plannedWorkout in
|
||||
HStack {
|
||||
VStack(alignment: .leading) {
|
||||
Text(plannedWorkout.onDate.plannedDate?.weekDay ?? "-")
|
||||
.font(.title)
|
||||
|
||||
Text(plannedWorkout.onDate.plannedDate?.monthString ?? "-")
|
||||
.font(.title)
|
||||
|
||||
Text(plannedWorkout.onDate.plannedDate?.dateString ?? "-")
|
||||
.font(.title)
|
||||
}
|
||||
|
||||
Divider()
|
||||
|
||||
VStack {
|
||||
Text(plannedWorkout.workout.name)
|
||||
.font(.title)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
|
||||
Text(plannedWorkout.workout.description ?? "")
|
||||
.font(.body)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
|
||||
Text(plannedWorkout.onDate)
|
||||
.font(.footnote)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func maybeUpdateShit() {
|
||||
if UserStore.shared.token != nil{
|
||||
if UserStore.shared.plannedWorkouts.isEmpty {
|
||||
UserStore.shared.fetchPlannedWorkouts()
|
||||
}
|
||||
|
||||
if needsUpdating {
|
||||
DataStore.shared.fetchAllData()
|
||||
dataStore.fetchAllData()
|
||||
|
||||
AllWorkoutFetchable().fetch(completion: { result in
|
||||
needsUpdating = false
|
||||
|
||||
95
Werkout_ios/Views/PlanWorkoutView.swift
Normal file
95
Werkout_ios/Views/PlanWorkoutView.swift
Normal file
@@ -0,0 +1,95 @@
|
||||
//
|
||||
// PlanWorkoutView.swift
|
||||
// Werkout_ios
|
||||
//
|
||||
// Created by Trey Tartt on 7/2/23.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct PlanWorkoutView: View {
|
||||
@State var selectedDate = Date()
|
||||
let workout: Workout
|
||||
@Environment(\.dismiss) var dismiss
|
||||
var addedPlannedWorkout: (() -> Void)?
|
||||
|
||||
var body: some View {
|
||||
VStack() {
|
||||
Text(workout.name)
|
||||
.font(.title)
|
||||
|
||||
Text(selectedDate.formatted(date: .abbreviated, time: .omitted))
|
||||
.font(.system(size: 28))
|
||||
.bold()
|
||||
.foregroundColor(Color.accentColor)
|
||||
.padding()
|
||||
.animation(.spring(), value: selectedDate)
|
||||
.frame(width: 500)
|
||||
|
||||
Divider().frame(height: 1)
|
||||
|
||||
DatePicker("Select Date", selection: $selectedDate, displayedComponents: [.date])
|
||||
.padding(.horizontal)
|
||||
.datePickerStyle(.graphical)
|
||||
|
||||
Divider()
|
||||
|
||||
HStack {
|
||||
Button(action: {
|
||||
planWorkout()
|
||||
}, label: {
|
||||
Image(systemName: "plus.app")
|
||||
.font(.title)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
})
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
.frame(height: 44)
|
||||
.foregroundColor(.blue)
|
||||
.background(.yellow)
|
||||
.cornerRadius(8)
|
||||
.padding()
|
||||
|
||||
Button(action: {
|
||||
dismiss()
|
||||
}, label: {
|
||||
Image(systemName: "xmark.octagon.fill")
|
||||
.font(.title)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
})
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
.frame(height: 44)
|
||||
.foregroundColor(.white)
|
||||
.background(.red)
|
||||
.cornerRadius(8)
|
||||
.padding()
|
||||
}
|
||||
|
||||
Spacer()
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
|
||||
func planWorkout() {
|
||||
let postData = [
|
||||
"on_date": selectedDate.formatForPlannedWorkout,
|
||||
"workout": workout.id
|
||||
] as [String : Any]
|
||||
|
||||
PlanWorkoutFetchable(postData: postData).fetch(completion: { result in
|
||||
switch result {
|
||||
case .success(_):
|
||||
UserStore.shared.fetchPlannedWorkouts()
|
||||
dismiss()
|
||||
addedPlannedWorkout?()
|
||||
case .failure(_):
|
||||
fatalError("shit broke")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
struct PlanWorkoutView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
PlanWorkoutView(workout: PreviewData.workout())
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@ struct WorkoutDetailView: View {
|
||||
}
|
||||
|
||||
@State var presentedSheet: Sheet?
|
||||
@State var workoutToPlan: Workout?
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
@@ -35,6 +36,8 @@ struct WorkoutDetailView: View {
|
||||
ActionsView(completedWorkout: {
|
||||
bridgeModule.workoutEndDate = Date()
|
||||
bridgeModule.sendWorkoutCompleteToWatch()
|
||||
}, planWorkout: { workout in
|
||||
workoutToPlan = workout
|
||||
}, workout: workout)
|
||||
.frame(height: 44)
|
||||
|
||||
@@ -49,6 +52,11 @@ struct WorkoutDetailView: View {
|
||||
})
|
||||
}
|
||||
}
|
||||
.sheet(item: $workoutToPlan) { workout in
|
||||
PlanWorkoutView(workout: workout, addedPlannedWorkout: {
|
||||
dismiss()
|
||||
})
|
||||
}
|
||||
.interactiveDismissDisabled()
|
||||
}
|
||||
}
|
||||
@@ -107,6 +115,7 @@ struct InfoView: View {
|
||||
struct ActionsView: View {
|
||||
@ObservedObject var bridgeModule = BridgeModule.shared
|
||||
var completedWorkout: (() -> Void)?
|
||||
var planWorkout: ((Workout) -> Void)?
|
||||
|
||||
var workout: Workout
|
||||
@Environment(\.dismiss) var dismiss
|
||||
@@ -126,6 +135,17 @@ struct ActionsView: View {
|
||||
.background(.red)
|
||||
.foregroundColor(.white)
|
||||
|
||||
Button(action: {
|
||||
planWorkout?(workout)
|
||||
}, label: {
|
||||
Image(systemName: "calendar.badge.plus")
|
||||
.font(.title)
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
})
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.background(.blue)
|
||||
.foregroundColor(.white)
|
||||
|
||||
Button(action: {
|
||||
startWorkout()
|
||||
}, label: {
|
||||
@@ -162,8 +182,6 @@ struct ActionsView: View {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
func nextExercise() {
|
||||
bridgeModule.nextExercise()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user