wip
This commit is contained in:
@ -1,13 +1,96 @@
|
||||
|
||||
import SwiftUI
|
||||
import SwiftData
|
||||
|
||||
struct ExerciseAddEditView: View {
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@Environment(\.modelContext) private var modelContext
|
||||
|
||||
@Bindable var model: Exercise
|
||||
@Query(sort: [SortDescriptor(\ExerciseType.name)]) var exerciseTypes: [ExerciseType]
|
||||
|
||||
@State var model: Exercise
|
||||
|
||||
init(model: Exercise? = nil) {
|
||||
_model = State(initialValue: model ?? Exercise(name: "", setup: "", descr: "", sets: 3, reps: 10, weight: 30))
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
Text("Add/Edit Exercise")
|
||||
.navigationTitle("Exercise")
|
||||
Form {
|
||||
Section (header: Text("Name")) {
|
||||
TextField("Name", text: $model.name)
|
||||
.bold()
|
||||
}
|
||||
|
||||
Section (header: Text("Exercise Type")) {
|
||||
Picker("Type", selection: $model.type) {
|
||||
Text("Select a type").tag(nil as ExerciseType?)
|
||||
ForEach(exerciseTypes) { type in
|
||||
Text(type.name).tag(type as ExerciseType?)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Section(header: Text("Description")) {
|
||||
TextEditor(text: $model.descr)
|
||||
.frame(minHeight: 100)
|
||||
.padding(.vertical, 4)
|
||||
}
|
||||
|
||||
|
||||
Section (header: Text("Setup")) {
|
||||
TextEditor(text: $model.setup)
|
||||
.frame(minHeight: 100)
|
||||
.padding(.vertical, 4)
|
||||
// } footer: {
|
||||
// Text("Describe concisely how equipment should be configured")
|
||||
}
|
||||
|
||||
Section (header: Text("Weight")) {
|
||||
HStack {
|
||||
Text("\(model.weight)")
|
||||
.bold()
|
||||
Text("lbs")
|
||||
Spacer()
|
||||
Stepper("", value: $model.weight, in: 0...1000)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Section(header: Text("Target Muscles")) {
|
||||
// Button(action: {
|
||||
// showingMuscleSelection = true
|
||||
// }) {
|
||||
// HStack {
|
||||
// if selectedMuscles.isEmpty {
|
||||
// Text("None selected")
|
||||
// .foregroundColor(.secondary)
|
||||
// } else {
|
||||
// Text(selectedMuscles.map { $0.name }.joined(separator: ", "))
|
||||
// .foregroundColor(.primary)
|
||||
// .multilineTextAlignment(.leading)
|
||||
// }
|
||||
// Spacer()
|
||||
// Image(systemName: "chevron.right")
|
||||
// .foregroundColor(.secondary)
|
||||
// .font(.caption)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .navigationBarLeading) {
|
||||
Button("Cancel") {
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
Button("Save") {
|
||||
try? modelContext.save()
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ struct ExercisesListView: View {
|
||||
|
||||
@Query(sort: [SortDescriptor(\ExerciseType.name)]) var groups: [ExerciseType]
|
||||
|
||||
@State var showingAddSheet = false
|
||||
@State var itemToEdit: Exercise? = nil
|
||||
@State var itemToDelete: Exercise? = nil
|
||||
|
||||
@ -53,6 +54,18 @@ struct ExercisesListView: View {
|
||||
}
|
||||
}
|
||||
.navigationTitle("Exercises")
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
Button(action: {
|
||||
showingAddSheet.toggle()
|
||||
}) {
|
||||
Image(systemName: "plus")
|
||||
}
|
||||
}
|
||||
}
|
||||
.sheet(isPresented: $showingAddSheet) {
|
||||
ExerciseAddEditView()
|
||||
}
|
||||
.sheet(item: $itemToEdit) { item in
|
||||
ExerciseAddEditView(model: item)
|
||||
}
|
||||
|
@ -13,7 +13,11 @@ struct MuscleGroupAddEditView: View {
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@Environment(\.modelContext) private var modelContext
|
||||
|
||||
@Bindable var model: MuscleGroup
|
||||
@State var model: MuscleGroup
|
||||
|
||||
init(model: MuscleGroup? = nil) {
|
||||
_model = State(initialValue: model ?? MuscleGroup(name: "", descr: ""))
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
@ -38,6 +42,9 @@ struct MuscleGroupAddEditView: View {
|
||||
|
||||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
Button("Save") {
|
||||
if model.modelContext == nil {
|
||||
modelContext.insert(model)
|
||||
}
|
||||
try? modelContext.save()
|
||||
dismiss()
|
||||
}
|
||||
|
@ -15,56 +15,67 @@ struct MuscleGroupsListView: View {
|
||||
|
||||
@Query(sort: [SortDescriptor(\MuscleGroup.name)]) var items: [MuscleGroup]
|
||||
|
||||
@State var showingAddSheet = false
|
||||
@State var itemToEdit: MuscleGroup? = nil
|
||||
@State var itemToDelete: MuscleGroup? = nil
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
Form {
|
||||
List {
|
||||
ForEach (items) { item in
|
||||
ListItem(title: item.name, count: item.muscles?.count)
|
||||
.swipeActions(edge: .trailing, allowsFullSwipe: false) {
|
||||
Button (role: .destructive) {
|
||||
itemToDelete = item
|
||||
} label: {
|
||||
Label("Delete", systemImage: "trash")
|
||||
}
|
||||
Button {
|
||||
itemToEdit = item
|
||||
} label: {
|
||||
Label("Edit", systemImage: "pencil")
|
||||
}
|
||||
.tint(.indigo)
|
||||
Form {
|
||||
List {
|
||||
ForEach (items) { item in
|
||||
ListItem(title: item.name, count: item.muscles?.count)
|
||||
.swipeActions(edge: .trailing, allowsFullSwipe: false) {
|
||||
Button (role: .destructive) {
|
||||
itemToDelete = item
|
||||
} label: {
|
||||
Label("Delete", systemImage: "trash")
|
||||
}
|
||||
}
|
||||
Button {
|
||||
itemToEdit = item
|
||||
} label: {
|
||||
Label("Edit", systemImage: "pencil")
|
||||
}
|
||||
.tint(.indigo)
|
||||
}
|
||||
}
|
||||
.navigationTitle("Muscle Groups")
|
||||
}
|
||||
.sheet(item: $itemToEdit) {item in
|
||||
MuscleGroupAddEditView(model: item)
|
||||
}
|
||||
.confirmationDialog(
|
||||
"Delete?",
|
||||
isPresented: Binding<Bool>(
|
||||
get: { itemToDelete != nil },
|
||||
set: { if !$0 { itemToDelete = nil } }
|
||||
),
|
||||
titleVisibility: .visible
|
||||
) {
|
||||
Button("Delete", role: .destructive) {
|
||||
if let itemToDelete = itemToDelete {
|
||||
modelContext.delete(itemToDelete)
|
||||
try? modelContext.save()
|
||||
self.itemToDelete = nil
|
||||
}
|
||||
}
|
||||
.navigationTitle("Muscle Groups")
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
Button(action: {
|
||||
showingAddSheet.toggle()
|
||||
}) {
|
||||
Image(systemName: "plus")
|
||||
}
|
||||
Button("Cancel", role: .cancel) {
|
||||
itemToDelete = nil
|
||||
}
|
||||
} message: {
|
||||
Text("Are you sure you want to delete \(itemToDelete?.name ?? "this item")?")
|
||||
}
|
||||
}
|
||||
.sheet(isPresented: $showingAddSheet) {
|
||||
MuscleGroupAddEditView()
|
||||
}
|
||||
.sheet(item: $itemToEdit) {item in
|
||||
MuscleGroupAddEditView(model: item)
|
||||
}
|
||||
.confirmationDialog(
|
||||
"Delete?",
|
||||
isPresented: Binding<Bool>(
|
||||
get: { itemToDelete != nil },
|
||||
set: { if !$0 { itemToDelete = nil } }
|
||||
),
|
||||
titleVisibility: .visible
|
||||
) {
|
||||
Button("Delete", role: .destructive) {
|
||||
if let itemToDelete = itemToDelete {
|
||||
modelContext.delete(itemToDelete)
|
||||
try? modelContext.save()
|
||||
self.itemToDelete = nil
|
||||
}
|
||||
}
|
||||
Button("Cancel", role: .cancel) {
|
||||
itemToDelete = nil
|
||||
}
|
||||
} message: {
|
||||
Text("Are you sure you want to delete \(itemToDelete?.name ?? "this item")?")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user