108 lines
3.6 KiB
Swift
108 lines
3.6 KiB
Swift
//
|
||
// SettingsView.swift
|
||
// Workouts
|
||
//
|
||
// Created by rzen on 7/13/25 at 10:24 AM.
|
||
//
|
||
// Copyright 2025 Rouslan Zenetl. All Rights Reserved.
|
||
//
|
||
|
||
import SwiftUI
|
||
import SwiftData
|
||
|
||
struct SettingsView: View {
|
||
@Environment(\.modelContext) private var modelContext
|
||
|
||
|
||
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 {
|
||
Form {
|
||
Section (header: Text("Lists")) {
|
||
NavigationLink(destination: SplitsListView()) {
|
||
HStack {
|
||
Text("Splits")
|
||
Spacer()
|
||
Text("\(splitsCount ?? 0)")
|
||
.font(.caption)
|
||
.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)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
.navigationTitle("Settings")
|
||
}
|
||
}
|
||
}
|
||
|
||
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)])
|
||
}
|
||
}
|