add WorkoutIconSelector, change the way adding ExerciseTemplate works to in-List
This commit is contained in:
@@ -51,10 +51,10 @@ struct AddExerciseToWorkoutListItem: View {
|
||||
}) {
|
||||
HStack {
|
||||
Text(exerciseTemplate.name)
|
||||
.foregroundColor(.black)
|
||||
.foregroundStyle(.black)
|
||||
Spacer()
|
||||
Image(systemName: "plus.circle.fill")
|
||||
.foregroundColor(.green)
|
||||
.foregroundStyle(.green)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ final class Workout {
|
||||
}
|
||||
|
||||
static let sampleData: [Workout] = [
|
||||
Workout(name: "RR", exercises: Exercise.sampleData)
|
||||
Workout(name: "Recommended Routine", exercises: Exercise.sampleData),
|
||||
Workout(name: "Marathon Plan", exercises: Exercise.sampleData)
|
||||
]
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ struct WorkoutDetail: View {
|
||||
|
||||
.navigationBarTitle("Edit \(workout.name)")
|
||||
.toolbar {
|
||||
ToolbarItem {
|
||||
ToolbarItem() {
|
||||
EditButton()
|
||||
}
|
||||
}
|
||||
@@ -83,7 +83,7 @@ struct WorkoutDetail: View {
|
||||
|
||||
struct ExerciseListItem: View {
|
||||
var workout: Workout
|
||||
var exercise: Exercise
|
||||
@State var exercise: Exercise
|
||||
|
||||
init(_ workout: Workout, _ exercise: Exercise ) {
|
||||
self.workout = workout
|
||||
@@ -92,18 +92,30 @@ struct ExerciseListItem: View {
|
||||
|
||||
var body: some View {
|
||||
Button(action: {
|
||||
// workout.addExercise(from: exercise)
|
||||
// workout.addExercise(from: exercise)
|
||||
}) {
|
||||
HStack {
|
||||
|
||||
// TextField("Enter Reps", text: $exercise.reps)
|
||||
// .keyboardType(.numberPad) // Set the keyboard to number pad
|
||||
// .padding()
|
||||
// .frame(width: 100, height: 50)
|
||||
// .background(Color(.systemGray6))
|
||||
// .cornerRadius(8)
|
||||
// .multilineTextAlignment(.center) // Center the text
|
||||
// .overlay(
|
||||
// RoundedRectangle(cornerRadius: 8)
|
||||
// .stroke(Color.gray, lineWidth: 1)
|
||||
// )
|
||||
Text(String(workout.exercises.filter { $0 == exercise }.count))
|
||||
.font(.system(size: 14, weight: .bold))
|
||||
.foregroundColor(.white)
|
||||
.foregroundStyle(.white)
|
||||
.frame(width: 20, height: 10)
|
||||
.padding(8)
|
||||
.background(Color.blue)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 8))
|
||||
Text(exercise.name)
|
||||
.foregroundColor(.black)
|
||||
.foregroundStyle(.black)
|
||||
Spacer()
|
||||
Image(systemName: "info.circle")
|
||||
}
|
||||
@@ -114,6 +126,6 @@ struct ExerciseListItem: View {
|
||||
#Preview {
|
||||
NavigationStack {
|
||||
WorkoutDetail(workout: Workout.sampleData.first!)
|
||||
.modelContainer(SampleData.shared.modelContainer)
|
||||
.modelContainer(SampleData.shared.modelContainer)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
//
|
||||
// WorkoutIconSelector.swift
|
||||
// WorkoutsPlus
|
||||
//
|
||||
// Created by Felix Förtsch on 26.08.24.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct WorkoutIconSelector: View {
|
||||
|
||||
@State private var selectedColor: Color = .black
|
||||
@State private var selectedIcon: String?
|
||||
@State private var searchText: String = ""
|
||||
|
||||
var filteredIcons: [String] {
|
||||
if searchText.isEmpty {
|
||||
return fitnessIcons
|
||||
} else {
|
||||
return fitnessIcons.filter { $0.contains(searchText.lowercased()) }
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
LazyVGrid(columns: [GridItem(.adaptive(minimum: 50))]) {
|
||||
ForEach(systemColors, id: \.self) { color in
|
||||
Button(action: {
|
||||
selectedColor = color
|
||||
}) {
|
||||
Circle()
|
||||
.fill(color)
|
||||
.frame(width: 40, height: 40)
|
||||
.overlay(
|
||||
Circle()
|
||||
.stroke(Color.white, lineWidth: selectedColor == color ? 4 : 0)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
LazyVGrid(columns: [GridItem(.adaptive(minimum: 50, maximum: 100))]) {
|
||||
ForEach(filteredIcons, id: \.self) { iconName in
|
||||
Button(action: {
|
||||
selectedIcon = iconName
|
||||
}) {
|
||||
Image(systemName: iconName)
|
||||
.foregroundStyle(selectedColor)
|
||||
.padding()
|
||||
.background()
|
||||
.cornerRadius(8)
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.searchable(text: $searchText)
|
||||
}
|
||||
|
||||
.navigationTitle("Select a Workout Icon")
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
NavigationView() {
|
||||
WorkoutIconSelector()
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ struct WorkoutLibrary: View {
|
||||
@State private var newWorkout: Workout?
|
||||
|
||||
var body: some View {
|
||||
NavigationSplitView {
|
||||
NavigationView {
|
||||
Group {
|
||||
if !workouts.isEmpty {
|
||||
List {
|
||||
@@ -27,6 +27,9 @@ struct WorkoutLibrary: View {
|
||||
}
|
||||
}
|
||||
.onDelete(perform: deleteWorkout)
|
||||
Button(action: addWorkout) {
|
||||
Label("Add Workout", systemImage: "plus")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ContentUnavailableView {
|
||||
@@ -34,16 +37,11 @@ struct WorkoutLibrary: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
.navigationBarTitle("Workout Templates")
|
||||
.navigationBarTitle("Workouts")
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .topBarLeading) {
|
||||
ToolbarItem() {
|
||||
EditButton()
|
||||
}
|
||||
ToolbarItem {
|
||||
Button(action: addWorkout) {
|
||||
Label("Add Workout", systemImage: "plus")
|
||||
}
|
||||
}
|
||||
}
|
||||
.sheet(item: $newWorkout) { workout in
|
||||
NavigationStack {
|
||||
@@ -52,10 +50,6 @@ struct WorkoutLibrary: View {
|
||||
.presentationDetents([.medium])
|
||||
.interactiveDismissDisabled()
|
||||
}
|
||||
} detail: {
|
||||
// TODO: What does this Detail do?
|
||||
Text("Select a workout")
|
||||
.navigationTitle("Movie")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user