change folders to the "feature" mindset
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
//
|
||||
// AddExerciseToWorkout.swift
|
||||
// WorkoutsPlus
|
||||
//
|
||||
// Created by Felix Förtsch on 22.08.24.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import SwiftData
|
||||
|
||||
struct WorkoutItemLibrarySheet: View {
|
||||
@Environment(\.modelContext) private var modelContext
|
||||
@Query(sort: \Exercise.name) private var exercises: [Exercise]
|
||||
|
||||
@State var workout: Workout
|
||||
// TODO: Add (i) Button that allows editing an exercise (maybe requires NavigationStack?)
|
||||
|
||||
// TODO: Pass in some context? So that when we come from a Set and add a Set, it's treed. Or when we come from a Set and add an Exercise, we put it into it's child
|
||||
var body: some View {
|
||||
Group {
|
||||
List {
|
||||
// Section(header: Text("Utilities")) {
|
||||
// AddItemButton(label: "Set") {
|
||||
// addWorkoutItemtoWorkout(WorkoutItem(set: [
|
||||
// WorkoutItem(Exercise("Set item 1")),
|
||||
// WorkoutItem(Exercise("Set item 2"))
|
||||
// ]))
|
||||
// }
|
||||
// AddItemButton(label: "Rest") {
|
||||
// addWorkoutItemtoWorkout(WorkoutItem(rest: 45))
|
||||
// }
|
||||
// }
|
||||
Section(header: Text("Excersises")) {
|
||||
if !exercises.isEmpty {
|
||||
ForEach(exercises) { exercise in
|
||||
AddItemButton(label: exercise.name) {
|
||||
let workoutItem = WorkoutItem(exercise)
|
||||
addWorkoutItemtoWorkout(workoutItem)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ContentUnavailableView {
|
||||
// TODO: Add Button that allows adding an exercise
|
||||
Label("No Exercises", systemImage: Exercise.systemImage)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.presentationDetents([.medium, .large])
|
||||
.presentationDragIndicator(.visible)
|
||||
}
|
||||
|
||||
private func addWorkoutItemtoWorkout(_ workoutItem: WorkoutItem) {
|
||||
workout.add(workoutItem: workoutItem)
|
||||
// TODO: Handle saving in a way the user knows when it's saved
|
||||
// modelContext.save()
|
||||
}
|
||||
}
|
||||
|
||||
#Preview("With Sample Data") {
|
||||
WorkoutItemLibrarySheet(workout: Workout.sampleData.first!)
|
||||
.modelContainer(SampleData.shared.modelContainer)
|
||||
}
|
||||
|
||||
#Preview("Empty Database") {
|
||||
WorkoutItemLibrarySheet(workout: Workout.sampleData.first!)
|
||||
.modelContainer(for: Exercise.self, inMemory: true)
|
||||
}
|
||||
Reference in New Issue
Block a user