wip
This commit is contained in:
@ -18,14 +18,9 @@ enum AppStorageKeys {
|
||||
struct SettingsView: View {
|
||||
@Environment(\.modelContext) private var modelContext
|
||||
|
||||
@State private var showingPopulateData = false
|
||||
@State private var showingClearAllDataConfirmation = false
|
||||
|
||||
var splitsCount: Int? { try? modelContext.fetchCount(FetchDescriptor<Split>()) }
|
||||
var musclesCount: Int? { try? modelContext.fetchCount(FetchDescriptor<Muscle>()) }
|
||||
var muscleGroupsCount: Int? { try? modelContext.fetchCount(FetchDescriptor<MuscleGroup>()) }
|
||||
var exerciseTypeCount: Int? { try? modelContext.fetchCount(FetchDescriptor<ExerciseType>()) }
|
||||
var exercisesCount: Int? { try? modelContext.fetchCount(FetchDescriptor<Exercise>()) }
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
@ -40,67 +35,9 @@ struct SettingsView: View {
|
||||
.foregroundColor(.gray)
|
||||
}
|
||||
}
|
||||
NavigationLink(destination: MuscleGroupsListView()) {
|
||||
HStack {
|
||||
Text("Muscle Groups")
|
||||
Spacer()
|
||||
Text("\(muscleGroupsCount ?? 0)")
|
||||
.font(.caption)
|
||||
.foregroundColor(.gray)
|
||||
}
|
||||
}
|
||||
NavigationLink(destination: MusclesListView()) {
|
||||
HStack {
|
||||
Text("Muscles")
|
||||
Spacer()
|
||||
Text("\(musclesCount ?? 0)")
|
||||
.font(.caption)
|
||||
.foregroundColor(.gray)
|
||||
}
|
||||
}
|
||||
NavigationLink(destination: ExerciseTypeListView()) {
|
||||
HStack {
|
||||
Text("Exercise Types")
|
||||
Spacer()
|
||||
Text("\(exerciseTypeCount ?? 0)")
|
||||
.font(.caption)
|
||||
.foregroundColor(.gray)
|
||||
}
|
||||
}
|
||||
NavigationLink(destination: ExercisesListView()) {
|
||||
HStack {
|
||||
Text("Exercises")
|
||||
Spacer()
|
||||
Text("\(exercisesCount ?? 0)")
|
||||
.font(.caption)
|
||||
.foregroundColor(.gray)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Section(header: Text("Developer")) {
|
||||
|
||||
Button(action: {
|
||||
showingPopulateData = true
|
||||
}) {
|
||||
HStack {
|
||||
Label("Populate Data", systemImage: "plus")
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
.confirmationDialog(
|
||||
"Populate Data?",
|
||||
isPresented: $showingPopulateData,
|
||||
titleVisibility: .hidden
|
||||
) {
|
||||
Button("Populate Data") {
|
||||
DataLoader.create(modelContext: modelContext)
|
||||
}
|
||||
Button("Cancel", role: .cancel) {}
|
||||
// } message: {
|
||||
// Text("This action cannot be undone. All data will be permanently deleted.")
|
||||
}
|
||||
|
||||
Button(action: {
|
||||
showingClearAllDataConfirmation = true
|
||||
}) {
|
||||
@ -139,10 +76,6 @@ struct SettingsView: View {
|
||||
|
||||
private func clearAllData () {
|
||||
do {
|
||||
try deleteAllObjects(ofType: ExerciseType.self, from: modelContext)
|
||||
try deleteAllObjects(ofType: Exercise.self, from: modelContext)
|
||||
try deleteAllObjects(ofType: Muscle.self, from: modelContext)
|
||||
try deleteAllObjects(ofType: MuscleGroup.self, from: modelContext)
|
||||
try deleteAllObjects(ofType: Split.self, from: modelContext)
|
||||
try deleteAllObjects(ofType: SplitExerciseAssignment.self, from: modelContext)
|
||||
try deleteAllObjects(ofType: Workout.self, from: modelContext)
|
||||
@ -154,30 +87,6 @@ struct SettingsView: View {
|
||||
}
|
||||
}
|
||||
|
||||
struct ExercisesListView: View {
|
||||
var body: some View {
|
||||
EntityListView<Exercise>(sort: [SortDescriptor(\Exercise.name)])
|
||||
}
|
||||
}
|
||||
|
||||
struct ExerciseTypeListView: View {
|
||||
var body: some View {
|
||||
EntityListView<ExerciseType>(sort: [SortDescriptor(\ExerciseType.name)])
|
||||
}
|
||||
}
|
||||
|
||||
struct MuscleGroupsListView: View {
|
||||
var body: some View {
|
||||
EntityListView<MuscleGroup>(sort: [SortDescriptor(\MuscleGroup.name)])
|
||||
}
|
||||
}
|
||||
|
||||
struct MusclesListView: View {
|
||||
var body: some View {
|
||||
EntityListView<Muscle>(sort: [SortDescriptor(\Muscle.name)])
|
||||
}
|
||||
}
|
||||
|
||||
struct SplitsListView: View {
|
||||
var body: some View {
|
||||
EntityListView<Split>(sort: [SortDescriptor(\Split.name)])
|
||||
|
Reference in New Issue
Block a user