Skip to content

Commit

Permalink
Fixes app
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimillian committed Oct 9, 2019
1 parent 720b28d commit 8c42827
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 18 deletions.
8 changes: 0 additions & 8 deletions CoachUI.xcodeproj/project.pbxproj
Expand Up @@ -76,7 +76,6 @@
children = (
69166E79231D1A7F00A5F192 /* launch */,
69166E7B231D1A9600A5F192 /* views */,
69166E8F231D712400A5F192 /* extensions */,
69166E7A231D1A9300A5F192 /* models */,
69166E6A231CF60B00A5F192 /* Assets.xcassets */,
69166E6F231CF60B00A5F192 /* LaunchScreen.storyboard */,
Expand Down Expand Up @@ -127,13 +126,6 @@
path = views;
sourceTree = "<group>";
};
69166E8F231D712400A5F192 /* extensions */ = {
isa = PBXGroup;
children = (
);
path = extensions;
sourceTree = "<group>";
};
69166E92231D788100A5F192 /* rows */ = {
isa = PBXGroup;
children = (
Expand Down
8 changes: 6 additions & 2 deletions CoachUI/models/WorkoutsStore.swift
Expand Up @@ -12,8 +12,8 @@ import SwiftUI
class WorkoutsStore: ObservableObject {
static var sharedStore : WorkoutsStore!

var workouts: [Workout] = []
var favorites: [String] = []
@Published var workouts: [Workout] = []
@Published var favorites: [String] = []

init() {
workouts.append(contentsOf: buildDefaultWorkouts())
Expand All @@ -27,6 +27,10 @@ class WorkoutsStore: ObservableObject {
workouts.append(workout)
}

func editWorkout(workout: Workout) {

}

func removeWorkout(at index: Int) {
let workout = workouts.remove(at: index)
favorites.removeAll{ $0 == workout.id }
Expand Down
27 changes: 21 additions & 6 deletions CoachUI/views/WorkoutCreatorView.swift
Expand Up @@ -12,6 +12,9 @@ struct WorkoutCreatorView: View {

//MARK: - Properties
@EnvironmentObject var store: WorkoutsStore
@Environment(\.presentationMode) var presentationMode

var editingWorkout: Workout?

@State private var workoutName = ""
@State private var exercises: [Exercise] = []
Expand All @@ -22,19 +25,25 @@ struct WorkoutCreatorView: View {
// MARK: - nav buttons
private var saveButton: some View {
Button(action: {
let workout = Workout(name: self.workoutName)
for exercise in self.exercises {
workout.addExercise(exercise: exercise)
if let editing = self.editingWorkout {
self.editingWorkout?.name = self.workoutName
self.editingWorkout?.exercises = self.exercises
} else {
let workout = Workout(name: self.workoutName)
for exercise in self.exercises {
workout.addExercise(exercise: exercise)
}
self.store.insertWorkout(workout: workout)
}
self.store.insertWorkout(workout: workout)
self.presentationMode.wrappedValue.dismiss()
}, label: {
Text("Save")
})
}

private var cancelButton: some View {
Button(action: {

self.presentationMode.wrappedValue.dismiss()
}, label: {
Text("Cancel")
.foregroundColor(.red)
Expand Down Expand Up @@ -97,11 +106,17 @@ struct WorkoutCreatorView: View {
}
addExerciseSection
}
.onAppear{
if let editing = self.editingWorkout {
self.workoutName = editing.name
self.exercises = editing.exercises
}
}
.navigationBarTitle("Create a new workout",
displayMode: .inline)
.navigationBarItems(leading: cancelButton, trailing: saveButton)

}
}.navigationViewStyle(StackNavigationViewStyle())
}
}

Expand Down
36 changes: 34 additions & 2 deletions CoachUI/views/WorkoutDetailView.swift
Expand Up @@ -10,7 +10,8 @@ import SwiftUI

struct WorkoutDetailView: View {
@EnvironmentObject var store: WorkoutsStore
let workout: Workout
@ObservedObject var workout: Workout
@State private var isWorkoutFormPresented = false

private var favButton: some View {
Button(action: {
Expand All @@ -21,6 +22,28 @@ struct WorkoutDetailView: View {
.foregroundColor(.yellow)
})
}

private var deleteButton: some View {
Button(action: {
if let index = self.store.workouts.firstIndex(of: self.workout) {
self.store.removeWorkout(at: index)
}
}, label: {
Image(systemName: "trash")
.imageScale(.large)
.foregroundColor(.red)
})
}


private var editButton: some View {
Button(action: {
self.isWorkoutFormPresented = true
}, label: {
Text("Edit").foregroundColor(.blue)
})
}

var body: some View {
List {
Section(header: Text("Exercices")) {
Expand All @@ -38,9 +61,18 @@ struct WorkoutDetailView: View {
}
}
}
.navigationBarItems(trailing: favButton)
.navigationBarItems(trailing:
HStack {
favButton.padding()
deleteButton
editButton
})
.listStyle(GroupedListStyle())
.navigationBarTitle(workout.name)
.sheet(isPresented: $isWorkoutFormPresented,
content: { WorkoutCreatorView(editingWorkout: self.workout).environmentObject(self.store)

})
}
}

Expand Down
3 changes: 3 additions & 0 deletions CoachUI/views/WorkoutTimer.swift
Expand Up @@ -49,6 +49,7 @@ struct WorkoutTimer: View {

var body: some View {
ZStack {
// Gradient
GeometryReader { geometry in
Path { (path) in
let size: CGFloat = min(geometry.size.width, geometry.size.height) * 0.7
Expand All @@ -62,6 +63,7 @@ struct WorkoutTimer: View {
endPoint: .init(x: 0.5, y: 0.6)
))
}
// Border
GeometryReader { geometry in
Path { (path) in
let size: CGFloat = min(geometry.size.width, geometry.size.height) * 0.7
Expand All @@ -71,6 +73,7 @@ struct WorkoutTimer: View {

}.stroke(lineWidth: 10).foregroundColor(Color.gray)
}
// Progress
GeometryReader { geometry in
Path { (path) in
let size: CGFloat = min(geometry.size.width, geometry.size.height) * 0.7
Expand Down

0 comments on commit 8c42827

Please sign in to comment.