Updated the ContentView view in the app target to support navigation split view and to show floating new task button on both sidebar and details views when required.

This commit is contained in:
2026-02-12 04:08:30 +01:00
parent 1e7e498b47
commit c02f027687
5 changed files with 117 additions and 25 deletions
+29 -20
View File
@@ -4,13 +4,14 @@ import SwiftUI
/// The main content view of the app.
///
/// This view serves as the primary interface for managing todo tasks.
///
/// The view uses a dedicated view model (`ViewModel`) to manage state and business logic, following the MVVM pattern.
/// User interactions are handled through the view model, maintaining separation of concerns.
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()
@@ -19,30 +20,38 @@ struct ContentView: View {
/// The content and behavior of the view.
///
/// Displays a navigation view containing:
/// 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 when `viewModel.newTaskShown` is true,
/// allowing users to create new todo tasks.
/// The view presents a sheet to allow users to create new todo tasks.
var body: some View {
NavigationView {
ZStack(alignment: .bottomTrailing) {
TaskGroupListView()
Button(action: viewModel.showNewTask) {
Image(systemName: "plus")
.frame(width: 48, height: 48)
.foregroundStyle(.white)
NavigationSplitView {
TaskGroupListView($viewModel.group)
.newTaskButton(show: viewModel.showNewTaskButtonInSidebar(when: horizontalSizeClass)) {
viewModel.showNewTask()
}
.glassEffect(.regular.tint(.blue.opacity(0.8)).interactive())
.padding(.trailing, 20)
} 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")
)
}
.navigationTitle("Todos")
}
.sheet(isPresented: $viewModel.newTaskShown) {
NewTaskView()
}
}
}
// MARK: - Previews