This commit is contained in:
Trey t
2023-07-05 17:36:20 -05:00
parent 648ef93d23
commit 52ab089c12
6 changed files with 158 additions and 67 deletions

View File

@@ -23,7 +23,7 @@ struct AllWorkoutsView: View {
}
}
}
@State var isUpdating = false
@State var workouts: [Workout]?
var bridgeModule = BridgeModule.shared
@State public var needsUpdating: Bool = true
@@ -52,28 +52,32 @@ struct AllWorkoutsView: View {
var body: some View {
ZStack {
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)
}
VStack {
Picker("", selection: $selectedSegment) {
ForEach(MainViews.allCases, id: \.self) { viewType in
Text(viewType.title)
}
.pickerStyle(.segmented)
.padding()
}
.pickerStyle(.segmented)
.padding()
switch selectedSegment {
case .AllWorkout:
switch selectedSegment {
case .AllWorkout:
AllWorkoutsListView(workouts: workouts, selectedWorkout: { workout in
selectedWorkout = workout
})
Divider()
case .MyWorkouts:
plannedWorkout(workouts: UserStore.shared.plannedWorkouts)
if isUpdating {
ProgressView()
.progressViewStyle(.circular)
}
AllWorkoutsListView(workouts: workouts, selectedWorkout: { workout in
selectedWorkout = workout
}, refresh: {
self.needsUpdating = true
maybeUpdateShit()
})
Divider()
case .MyWorkouts:
plannedWorkout(workouts: UserStore.shared.plannedWorkouts)
}
}
} else {
@@ -150,6 +154,7 @@ struct AllWorkoutsView: View {
}
if needsUpdating {
self.isUpdating = true
dataStore.fetchAllData()
AllWorkoutFetchable().fetch(completion: { result in
@@ -158,9 +163,12 @@ struct AllWorkoutsView: View {
case .success(let model):
DispatchQueue.main.async {
self.workouts = model
self.isUpdating = false
}
case .failure(_):
fatalError("shit broke")
DispatchQueue.main.async {
self.isUpdating = false
}
}
})
}
@@ -197,6 +205,7 @@ struct AllWorkoutsListView: View {
return workouts
}
}
var refresh: (() -> Void)
var body: some View {
VStack {
@@ -233,6 +242,9 @@ struct AllWorkoutsListView: View {
}
}
}
.refreshable {
refresh()
}
TextField("Filter", text: $searchString)
.padding(.leading)
}