This commit is contained in:
Trey t
2023-06-25 22:00:59 -05:00
parent d055ed182d
commit f40c40c9bb
9 changed files with 220 additions and 87 deletions

View File

@@ -49,6 +49,17 @@ struct AccountView: View {
}
}
Spacer()
Button("Logout", action: {
userStore.logout()
})
.frame(maxWidth: .infinity, alignment: .center)
.frame(height: 44)
.foregroundColor(.white)
.background(.red)
.cornerRadius(8)
.padding()
.frame(maxWidth: .infinity)
}
.padding()
.onAppear{

View File

@@ -24,9 +24,16 @@ struct AddExerciseView: View {
var selectedWorkout: ((ExerciseExercise) -> Void)
@State var createWorkoutItemPickerViewModel: CreateWorkoutItemPickerViewModel?
@State var createWorkoutItemPickerViewType: CreateWorkoutItemPickerViewType?
@State var searchString: String = ""
var body: some View {
VStack {
exerciseView()
.padding(.top)
TextField("Filter", text: $searchString)
.padding()
HStack {
muscleView()
.frame(maxWidth: .infinity)
@@ -38,9 +45,6 @@ struct AddExerciseView: View {
}
.padding(.top)
.frame(height: 44)
exerciseView()
.padding(.top)
}
.onAppear{
if #function.hasPrefix("__preview") {
@@ -190,25 +194,27 @@ struct AddExerciseView: View {
List() {
ForEach(filteredExercises.indices, id: \.self) { i in
let obj = filteredExercises[i]
VStack {
Text(obj.name)
.frame(maxWidth: .infinity, alignment: .leading)
if obj.side.count > 0 {
Text(obj.side)
if searchString.isEmpty || obj.name.lowercased().contains(searchString.lowercased()) {
VStack {
Text(obj.name)
.frame(maxWidth: .infinity, alignment: .leading)
if obj.side.count > 0 {
Text(obj.side)
.font(.footnote)
.frame(maxWidth: .infinity, alignment: .leading)
}
Text(obj.equipmentRequired)
.font(.footnote)
.frame(maxWidth: .infinity, alignment: .leading)
Text(obj.muscleGroups)
.font(.footnote)
.frame(maxWidth: .infinity, alignment: .leading)
}
Text(obj.equipmentRequired)
.font(.footnote)
.frame(maxWidth: .infinity, alignment: .leading)
Text(obj.muscleGroups)
.font(.footnote)
.frame(maxWidth: .infinity, alignment: .leading)
}
.contentShape(Rectangle())
.onTapGesture {
selectedWorkout(obj)
dismiss()
.contentShape(Rectangle())
.onTapGesture {
selectedWorkout(obj)
dismiss()
}
}
}
}

View File

@@ -21,6 +21,8 @@ struct AllWorkoutsView: View {
}
}
@State private var showLoginView = false
let pub = NotificationCenter.default.publisher(for: NSNotification.Name("CreatedNewWorkout"))
var body: some View {
@@ -45,34 +47,45 @@ struct AllWorkoutsView: View {
Text("no workouts")
}
}.onAppear{
if needsUpdating {
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")
}
})
}
maybeUpdateShit()
}
.sheet(item: $selectedWorkout) { item in
let viewModel = WorkoutDetailViewModel(workout: item)
WorkoutDetailView(viewModel: viewModel)
}
.sheet(isPresented: $showLoginView) {
LoginView(completion: {
self.needsUpdating = true
maybeUpdateShit()
})
}
.onReceive(pub) { (output) in
self.needsUpdating = true
maybeUpdateShit()
}
}
func maybeUpdateShit() {
if UserStore.shared.token != nil{
if needsUpdating {
DataStore.shared.fetchAllData()
AllWorkoutFetchable().fetch(completion: { result in
needsUpdating = false
switch result {
case .success(let model):
DispatchQueue.main.async {
self.workouts = model
}
case .failure(_):
fatalError("shit broke")
}
})
} else {
fatalError("shit broke")
}
} else {
showLoginView = true
}
}
}

View File

@@ -43,7 +43,6 @@ struct CompletedWorkoutView: View {
.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: {

View File

@@ -17,33 +17,6 @@ struct CreateWorkoutMainView: View {
TextField("Title", text: $viewModel.title)
.padding()
HStack {
Button("Add Superset", action: {
viewModel.addNewSuperset()
})
.frame(maxWidth: .infinity, alignment: .center)
.frame(height: 44)
.foregroundColor(.blue)
.background(.yellow)
.cornerRadius(8)
.padding()
.frame(maxWidth: .infinity)
Divider()
Button("Done", action: {
viewModel.uploadWorkout()
})
.frame(maxWidth: .infinity, alignment: .center)
.frame(height: 44)
.foregroundColor(.white)
.background(.blue)
.cornerRadius(8)
.padding()
.frame(maxWidth: .infinity)
}
.frame(height: 44)
List() {
ForEach($viewModel.superSets, id: \.id) { superset in
Section {
@@ -86,6 +59,35 @@ struct CreateWorkoutMainView: View {
}
.listRowSeparator(.hidden)
}
HStack {
Button("Add Superset", action: {
viewModel.addNewSuperset()
})
.frame(maxWidth: .infinity, alignment: .center)
.frame(height: 44)
.foregroundColor(.blue)
.background(.yellow)
.cornerRadius(8)
.padding()
.frame(maxWidth: .infinity)
Divider()
Button("Done", action: {
viewModel.uploadWorkout()
})
.frame(maxWidth: .infinity, alignment: .center)
.frame(height: 44)
.foregroundColor(.white)
.background(.blue)
.cornerRadius(8)
.padding()
.frame(maxWidth: .infinity)
.disabled(viewModel.title.isEmpty)
}
.frame(height: 44)
.padding(.bottom)
}
.sheet(isPresented: $showAddExercise) {
AddExerciseView(selectedWorkout: { exercise in

View File

@@ -22,26 +22,25 @@ struct CreateWorkoutSupersetActionsView: View {
Text("Add exercise")
.padding()
}
.frame(maxWidth: .infinity)
.foregroundColor(.white)
.background(.green)
.cornerRadius(10)
.frame(maxWidth: .infinity, alignment: .center)
.buttonStyle(BorderlessButtonStyle())
// Button(action: {
// if let selectedCreateWorkoutSuperSet = selectedCreateWorkoutSuperSet {
// viewModel.delete(superset: selectedCreateWorkoutSuperSet)
// viewModel.objectWillChange.send()
// }
// }) {
// Text("Delete superset")
// .padding()
// }
// .frame(maxWidth: .infinity)
// .foregroundColor(.white)
// .background(.red)
// .cornerRadius(10)
// .frame(maxWidth: .infinity, alignment: .center)
Button(action: {
viewModel.delete(superset: workoutSuperSet)
viewModel.objectWillChange.send()
}) {
Text("Delete superset")
.padding()
}
.foregroundColor(.white)
.background(.red)
.cornerRadius(10)
.frame(maxWidth: .infinity, alignment: .center)
.buttonStyle(BorderlessButtonStyle())
}
}
}

View File

@@ -0,0 +1,73 @@
//
// LoginView.swift
// Werkout_ios
//
// Created by Trey Tartt on 6/25/23.
//
import SwiftUI
struct LoginView: View {
@State var email: String = ""
@State var password: String = ""
@Environment(\.dismiss) var dismiss
let completion: (() -> Void)
var body: some View {
VStack {
Text("Login")
.font(.title)
TextField("Email", text: $email)
.autocapitalization(.none)
.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)
TextField("Password", text: $password)
.autocapitalization(.none)
.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)
Button("Login", action: {
login()
})
.frame(maxWidth: .infinity, alignment: .center)
.frame(height: 44)
.foregroundColor(.blue)
.background(.yellow)
.cornerRadius(8)
.padding()
.frame(maxWidth: .infinity)
Spacer()
}
.padding()
}
func login() {
let postData = [
"email": email,
"password": password
]
UserStore.shared.login(postData: postData, completion: { success in
if success {
completion()
dismiss()
}
})
}
}
struct LoginView_Previews: PreviewProvider {
static var previews: some View {
LoginView(completion: {
})
}
}