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:
@@ -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
|
||||
|
||||
@@ -7,9 +7,6 @@ import SwiftUI
|
||||
/// - *Title* (required)
|
||||
/// - *Note* (optional)
|
||||
/// - *Due date* (required)
|
||||
///
|
||||
/// The view uses a dedicated view model (`ViewModel`) to manage state and business logic, following the MVVM pattern.
|
||||
/// When the user saves, the todo is inserted into the SwiftData model context and the view is dismissed afterwards.
|
||||
struct NewTaskView: View {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
@@ -4,7 +4,6 @@ import SwiftUI
|
||||
/// A view that displays filtered todo tasks for a specific task group.
|
||||
///
|
||||
/// This view provides the presentation layer for displaying and managing tasks within a specific group category.
|
||||
/// It follows the MVVM pattern, delegating business logic to a view model and data fetching to a separate content view.
|
||||
struct TaskListView: View {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
Reference in New Issue
Block a user