This PR contains the work done to implement the **Group Task** feature, and to integrate it into the main content view of the app. Furthermore, an issue related to triggering a view update after inserting the todo tasks into the model container has been fixed. Reviewed-on: rock-n-code/todos-app#3 Co-authored-by: Javier Cicchelli <javier@rock-n-code.com> Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
53 lines
1.5 KiB
Swift
53 lines
1.5 KiB
Swift
import SwiftData
|
|
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 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 view containing:
|
|
/// - 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.
|
|
var body: some View {
|
|
NavigationView {
|
|
ZStack(alignment: .bottomTrailing) {
|
|
TaskGroupListView()
|
|
|
|
Button(action: viewModel.showNewTask) {
|
|
Image(systemName: "plus")
|
|
.frame(width: 48, height: 48)
|
|
.foregroundStyle(.white)
|
|
}
|
|
.glassEffect(.regular.tint(.blue.opacity(0.8)).interactive())
|
|
.padding(.trailing, 20)
|
|
}
|
|
.navigationTitle("Todos")
|
|
}
|
|
.sheet(isPresented: $viewModel.newTaskShown) {
|
|
NewTaskView()
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - Previews
|
|
|
|
#Preview {
|
|
ContentView()
|
|
}
|