add WorkoutIconSelector, change the way adding ExerciseTemplate works to in-List
This commit is contained in:
@@ -12,12 +12,16 @@ struct ExerciseLibrary: View {
|
||||
@Environment(\.modelContext) private var modelContext
|
||||
@Query(sort: \ExerciseTemplate.name) private var exerciseTemplates: [ExerciseTemplate]
|
||||
|
||||
@State private var newExercise: ExerciseTemplate?
|
||||
@State private var newExerciseTemplate: ExerciseTemplate = ExerciseTemplate("")
|
||||
@State private var newExerciseName: String = ""
|
||||
@State private var isAddingExerciseTemplate: Bool = false
|
||||
|
||||
@FocusState private var isInputFieldFocused: Bool
|
||||
|
||||
// TODO: Add search bar to the top
|
||||
|
||||
var body: some View {
|
||||
NavigationSplitView {
|
||||
NavigationView {
|
||||
Group {
|
||||
if !exerciseTemplates.isEmpty {
|
||||
List {
|
||||
@@ -29,6 +33,27 @@ struct ExerciseLibrary: View {
|
||||
}
|
||||
}
|
||||
.onDelete(perform: deleteExercise)
|
||||
if isAddingExerciseTemplate {
|
||||
TextField("New Exercise", text: $newExerciseName, onCommit: {
|
||||
newExerciseTemplate.name = newExerciseName
|
||||
saveExercise(exerciseTemplate: newExerciseTemplate)
|
||||
isAddingExerciseTemplate = false
|
||||
})
|
||||
.focused($isInputFieldFocused)
|
||||
}
|
||||
Button(action: {
|
||||
withAnimation {
|
||||
newExerciseTemplate = ExerciseTemplate("")
|
||||
newExerciseName = ""
|
||||
isAddingExerciseTemplate = true
|
||||
isInputFieldFocused = true
|
||||
}
|
||||
}) {
|
||||
HStack {
|
||||
Image(systemName: "plus.circle.fill")
|
||||
Text("Add Item")
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ContentUnavailableView {
|
||||
@@ -38,35 +63,10 @@ struct ExerciseLibrary: View {
|
||||
}
|
||||
.navigationBarTitle("Exercises")
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .topBarLeading) {
|
||||
ToolbarItem {
|
||||
EditButton()
|
||||
}
|
||||
ToolbarItem {
|
||||
Button(action: addExercise) {
|
||||
Label("Add Exercise", systemImage: "plus")
|
||||
}
|
||||
}
|
||||
}
|
||||
.sheet(item: $newExercise) { exercise in
|
||||
NavigationStack {
|
||||
AddExercise(exerciseTemplate: exercise)
|
||||
}
|
||||
// TODO: It's possible to add a boolean here ("Terms accepted y/n"). Maybe add this for empty string
|
||||
.presentationDetents([.medium])
|
||||
.interactiveDismissDisabled()
|
||||
}
|
||||
} detail: {
|
||||
// TODO: What does this Detail do?
|
||||
Text("Select a workout")
|
||||
.navigationTitle("Movie")
|
||||
}
|
||||
}
|
||||
|
||||
private func addExercise() {
|
||||
withAnimation {
|
||||
let item = ExerciseTemplate("")
|
||||
modelContext.insert(item)
|
||||
newExercise = item
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user