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

62 lines
1.8 KiB
Swift
Raw Normal View History

2026-02-08 18:01:45 +01:00
import SwiftData
2026-02-08 20:20:11 +00:00
import SwiftUI
2026-02-08 18:01:45 +01:00
2026-02-09 17:53:40 +00:00
/// The main content view of the app.
///
/// This view serves as the primary interface for managing todo tasks.
2026-02-08 18:01:45 +01:00
struct ContentView: View {
2026-02-08 20:20:11 +00:00
2026-02-09 17:53:40 +00:00
// MARK: Properties
2026-02-08 20:20:11 +00:00
/// The horizontal size class of the environment.
@Environment(\.horizontalSizeClass)
private var horizontalSizeClass
2026-02-09 17:53:40 +00:00
/// The view model managing the state and logic for this view.
@State
private var viewModel = ViewModel()
2026-02-08 18:01:45 +01:00
2026-02-09 17:53:40 +00:00
// 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
2026-02-09 17:53:40 +00:00
/// - A floating action button for adding new tasks
///
/// The view presents a sheet to allow users to create new todo tasks.
2026-02-08 18:01:45 +01:00
var body: some View {
NavigationSplitView {
TaskGroupListView($viewModel.group)
.newTaskButton(show: viewModel.showNewTaskButtonInSidebar(when: horizontalSizeClass)) {
viewModel.showNewTask()
2026-02-09 17:53:40 +00:00
}
} detail: {
if let group = viewModel.group {
TaskListView(group: group)
.newTaskButton(show: viewModel.showNewTaskButtonInDetails) {
viewModel.showNewTask()
}
.sheet(isPresented: $viewModel.newTaskShown) {
NewTaskView()
}
}
else {
ContentUnavailableView(
"Select a Group",
systemImage: "sidebar.left",
description: Text("Choose a task group from the sidebar")
)
2026-02-08 18:01:45 +01:00
}
}
}
2026-02-08 18:01:45 +01:00
}
2026-02-09 17:53:40 +00:00
// MARK: - Previews
2026-02-08 18:01:45 +01:00
#Preview {
ContentView()
}