add ActiveWorkoutSession logic, refactor Home, add additional sample data, add isDebug
This commit is contained in:
@@ -29,39 +29,39 @@ struct ExerciseLibrary: View {
|
||||
// TODO: Add search bar to the top
|
||||
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
Group {
|
||||
List {
|
||||
ForEach(filteredItems) { exercise in
|
||||
NavigationLink {
|
||||
ExerciseDetail(exercise: exercise)
|
||||
} label: {
|
||||
Text(exercise.name)
|
||||
}
|
||||
|
||||
Group {
|
||||
List {
|
||||
ForEach(filteredItems) { exercise in
|
||||
NavigationLink {
|
||||
ExerciseDetail(exercise: exercise)
|
||||
} label: {
|
||||
Text(exercise.name)
|
||||
}
|
||||
.onDelete(perform: deleteExercise)
|
||||
if isAddingExercise {
|
||||
TextField("New Exercise", text: $newExerciseName, onCommit: {
|
||||
newExercise.name = newExerciseName
|
||||
save(exercise: newExercise)
|
||||
isAddingExercise = false
|
||||
})
|
||||
.textInputAutocapitalization(.words)
|
||||
.focused($isInputFieldFocused)
|
||||
}
|
||||
AddItemButton(label: "Exercise", action: addExercise)
|
||||
}
|
||||
.searchable(text: $searchText)
|
||||
.onDelete(perform: deleteExercise)
|
||||
if isAddingExercise {
|
||||
TextField("New Exercise", text: $newExerciseName, onCommit: {
|
||||
newExercise.name = newExerciseName
|
||||
save(exercise: newExercise)
|
||||
isAddingExercise = false
|
||||
})
|
||||
.textInputAutocapitalization(.words)
|
||||
.focused($isInputFieldFocused)
|
||||
}
|
||||
AddItemButton(label: "Exercise", action: addExercise)
|
||||
}
|
||||
.navigationBarTitle("Exercises")
|
||||
.toolbar {
|
||||
ToolbarItem {
|
||||
EditButton()
|
||||
}
|
||||
.searchable(text: $searchText)
|
||||
}
|
||||
.navigationTitle("Exercises")
|
||||
.toolbar {
|
||||
ToolbarItem {
|
||||
EditButton()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private func addExercise() {
|
||||
withAnimation {
|
||||
newExercise = Exercise("")
|
||||
@@ -89,12 +89,17 @@ struct ExerciseLibrary: View {
|
||||
}
|
||||
|
||||
#Preview("With Sample Data") {
|
||||
ExerciseLibrary()
|
||||
.modelContainer(SampleData.shared.modelContainer)
|
||||
NavigationStack {
|
||||
ExerciseLibrary()
|
||||
}
|
||||
.modelContainer(SampleData.shared.modelContainer)
|
||||
|
||||
}
|
||||
|
||||
#Preview("Empty Database") {
|
||||
ExerciseLibrary()
|
||||
.modelContainer(for: WorkoutItem.self, inMemory: true)
|
||||
NavigationStack {
|
||||
ExerciseLibrary()
|
||||
}
|
||||
.modelContainer(for: WorkoutItem.self, inMemory: true)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user