Files
todos/App/Sources/Views/ContentView.swift
T

63 lines
1.8 KiB
Swift

import SwiftData
import SwiftUI
/// The main content view of the app.
///
/// This view serves as the primary interface for managing todo tasks.
struct ContentView: View {
// MARK: Properties
/// The horizontal size class of the environment.
@Environment(\.horizontalSizeClass)
private var horizontalSizeClass
/// The view model managing the state and logic for this view.
@State
private var viewModel = ViewModel()
// MARK: Body
/// The content and behavior of the view.
///
/// Displays a navigation split view with:
/// - Sidebar: List of todo task groups
/// - Detail: List of todo task related to a selected todo task group
/// - A floating action button for adding new tasks
///
/// The view presents a sheet to allow users to create new todo tasks.
var body: some View {
NavigationSplitView {
TaskGroupListView($viewModel.group)
.newTaskButton(show: viewModel.showNewTaskButtonInSidebar(when: horizontalSizeClass)) {
viewModel.showNewTask()
}
} detail: {
if let group = viewModel.group {
TaskListView(group: group)
.id(group)
.newTaskButton(show: viewModel.showNewTaskButtonInDetails) {
viewModel.showNewTask()
}
}
else {
ContentUnavailableView(
"view.content.content-unavailable.title",
systemImage: "sidebar.left",
description: Text("view.content.content-unavailable.description")
)
}
}
.sheet(isPresented: $viewModel.newTaskShown) {
NewTaskView()
}
}
}
// MARK: - Previews
#Preview {
ContentView()
}