add minimal workout interface, not linked with exercises yet
This commit is contained in:
@@ -10,7 +10,7 @@ import SwiftData
|
||||
|
||||
struct ExerciseLibraryView: View {
|
||||
@Environment(\.modelContext) private var modelContext
|
||||
@Query private var items: [Exercise]
|
||||
@Query private var exercises: [Exercise]
|
||||
|
||||
@State private var isPresentingNewItemSheet = false
|
||||
|
||||
@@ -25,15 +25,15 @@ struct ExerciseLibraryView: View {
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
List {
|
||||
ForEach(items.sorted(by: { $0.name < $1.name })) { item in
|
||||
NavigationLink(destination: ExerciseDetailsView(item: item)) {
|
||||
ForEach(exercises.sorted(by: { $0.name < $1.name })) { item in
|
||||
NavigationLink(destination: ExerciseDetailsView(exercise: item)) {
|
||||
Text(item.name)
|
||||
}
|
||||
}
|
||||
.onDelete(perform: deleteExercise)
|
||||
}
|
||||
.onAppear {
|
||||
if items.isEmpty {
|
||||
if exercises.isEmpty {
|
||||
loadInitialData(exercises: initialDataSet)
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,7 @@ struct ExerciseLibraryView: View {
|
||||
.sheet(isPresented: $isPresentingNewItemSheet) {
|
||||
let newItem = Exercise(name: "")
|
||||
NavigationView {
|
||||
ExerciseDetailsView(item: newItem, isPresentedAsSheet: true)
|
||||
ExerciseDetailsView(exercise: newItem, isPresentedAsSheet: true)
|
||||
.onDisappear {
|
||||
if !newItem.name.isEmpty {
|
||||
saveExercise(item: newItem)
|
||||
@@ -72,7 +72,7 @@ struct ExerciseLibraryView: View {
|
||||
private func deleteExercise(offsets: IndexSet) {
|
||||
withAnimation {
|
||||
for index in offsets {
|
||||
modelContext.delete(items[index])
|
||||
modelContext.delete(exercises[index])
|
||||
}
|
||||
try? modelContext.save()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user