WIP
This commit is contained in:
@@ -10,15 +10,19 @@ import SwiftUI
|
||||
|
||||
struct AllWorkoutsView: View {
|
||||
@State var workouts: [Workout]?
|
||||
@EnvironmentObject var bridgeModule: BridgeModule
|
||||
var bridgeModule = BridgeModule.shared
|
||||
@State public var needsUpdating: Bool = true
|
||||
|
||||
@State private var showWorkoutDetail = false
|
||||
@State private var selectedWorkout: Workout? {
|
||||
didSet {
|
||||
bridgeModule.currentWorkout = selectedWorkout
|
||||
showWorkoutDetail = true
|
||||
bridgeModule.currentWorkout = self.selectedWorkout
|
||||
}
|
||||
}
|
||||
|
||||
let pub = NotificationCenter.default.publisher(for: NSNotification.Name("CreatedNewWorkout"))
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
if let workouts = workouts {
|
||||
@@ -33,7 +37,7 @@ struct AllWorkoutsView: View {
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
selectedItem(workout: workout)
|
||||
selectedWorkout = workout
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,16 +45,19 @@ struct AllWorkoutsView: View {
|
||||
Text("no workouts")
|
||||
}
|
||||
}.onAppear{
|
||||
AllWorkoutFetchable().fetch(completion: { result in
|
||||
switch result {
|
||||
case .success(let model):
|
||||
DispatchQueue.main.async {
|
||||
self.workouts = model
|
||||
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):
|
||||
fatalError("shit broke")
|
||||
}
|
||||
case .failure(let failure):
|
||||
fatalError("shit broke")
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
.sheet(isPresented: $showWorkoutDetail) {
|
||||
if let selectedWorkout = selectedWorkout {
|
||||
@@ -58,12 +65,11 @@ struct AllWorkoutsView: View {
|
||||
WorkoutDetailView(viewModel: viewModel)
|
||||
}
|
||||
}
|
||||
.onReceive(pub) { (output) in
|
||||
self.needsUpdating = true
|
||||
}
|
||||
}
|
||||
|
||||
func selectedItem(workout: Workout) {
|
||||
selectedWorkout = workout
|
||||
}
|
||||
|
||||
|
||||
func testParse() {
|
||||
if let filepath = Bundle.main.path(forResource: "AllWorkouts", ofType: "json") {
|
||||
do {
|
||||
|
||||
Reference in New Issue
Block a user