WIP
This commit is contained in:
@@ -67,7 +67,10 @@ struct AllWorkoutsView: View {
|
||||
|
||||
switch selectedSegment {
|
||||
case .AllWorkout:
|
||||
allWorkoutView(workouts: workouts)
|
||||
AllWorkoutsListView(workouts: workouts, selectedWorkout: { workout in
|
||||
selectedWorkout = workout
|
||||
})
|
||||
Divider()
|
||||
case .MyWorkouts:
|
||||
plannedWorkout(workouts: UserStore.shared.plannedWorkouts)
|
||||
}
|
||||
@@ -101,24 +104,6 @@ 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
|
||||
@@ -185,6 +170,75 @@ struct AllWorkoutsView: View {
|
||||
}
|
||||
}
|
||||
|
||||
struct AllWorkoutsListView: View {
|
||||
@State var searchString: String = ""
|
||||
let workouts: [Workout]
|
||||
|
||||
let selectedWorkout: ((Workout) -> Void)
|
||||
|
||||
var filteredWorkouts: [Workout] {
|
||||
if !searchString.isEmpty, searchString.count > 0 {
|
||||
return workouts.filter({
|
||||
if $0.name.lowercased().contains(searchString.lowercased()) {
|
||||
return true
|
||||
}
|
||||
if let equipment = $0.equipment?.joined(separator: "").lowercased(),
|
||||
equipment.contains(searchString.lowercased()) {
|
||||
return true
|
||||
}
|
||||
if let muscles = $0.muscles?.joined(separator: "").lowercased(),
|
||||
muscles.contains(searchString.lowercased()) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
})
|
||||
} else {
|
||||
return workouts
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
List {
|
||||
ForEach(filteredWorkouts, id:\.name) { workout in
|
||||
Section {
|
||||
VStack {
|
||||
Text(workout.name)
|
||||
.font(.title2)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
Text(workout.description ?? "")
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
|
||||
if let muscles = workout.muscles,
|
||||
muscles.joined(separator: ", ").count > 0{
|
||||
Divider()
|
||||
Text(muscles.joined(separator: ", "))
|
||||
.font(.footnote)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
|
||||
if let equipment = workout.equipment,
|
||||
equipment.joined(separator: ", ").count > 0 {
|
||||
Divider()
|
||||
Text(equipment.joined(separator: ", "))
|
||||
.font(.footnote)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
selectedWorkout(workout)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
TextField("Filter", text: $searchString)
|
||||
.padding(.leading)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct AllWorkoutsView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
AllWorkoutsView(workouts: PreviewData.allWorkouts())
|
||||
|
||||
@@ -24,10 +24,9 @@ struct PlanWorkoutView: View {
|
||||
.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)
|
||||
|
||||
@@ -243,9 +243,25 @@ struct CurrentWorkoutElapsedTimeView: View {
|
||||
}
|
||||
|
||||
struct ExerciseListView: View {
|
||||
@AppStorage("showNSFWVideos") private var showNSFWVideos = false
|
||||
@ObservedObject var bridgeModule = BridgeModule.shared
|
||||
var workout: Workout
|
||||
|
||||
@State var avPlayer = AVPlayer(url: URL(string: "https://dev.werkout.fitness/media/exercise_videos/2_Dumbbell_Lateral_Lunges.mp4")!)
|
||||
@State var videoExercise: ExerciseExercise? {
|
||||
didSet {
|
||||
if showNSFWVideos {
|
||||
if let viddd = self.videoExercise?.nsfwVideoURL,
|
||||
let url = URL(string: BaseURLs.currentBaseURL + viddd) {
|
||||
avPlayer = AVPlayer(url: url)
|
||||
}
|
||||
} else {
|
||||
if let viddd = self.videoExercise?.videoURL,
|
||||
let url = URL(string: BaseURLs.currentBaseURL + viddd) {
|
||||
avPlayer = AVPlayer(url: url)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
List() {
|
||||
@@ -259,12 +275,17 @@ struct ExerciseListView: View {
|
||||
}
|
||||
|
||||
Text(obj.exercise.name)
|
||||
.onTapGesture {
|
||||
bridgeModule.goToExerciseAt(index: i)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
}
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
if bridgeModule.isInWorkout {
|
||||
bridgeModule.goToExerciseAt(index: i)
|
||||
} else {
|
||||
videoExercise = obj.exercise
|
||||
}
|
||||
}
|
||||
|
||||
if i == bridgeModule.currentExerciseIdx {
|
||||
HStack {
|
||||
if obj.exercise.isReps {
|
||||
@@ -284,6 +305,9 @@ struct ExerciseListView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
.sheet(item: $videoExercise) { exercise in
|
||||
VideoPlayerView(avPlayer: $avPlayer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user