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.
|
|
|
|
|
///
|
|
|
|
|
/// 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.
|
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
|
|
|
|
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 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.
|
2026-02-08 18:01:45 +01:00
|
|
|
var body: some View {
|
2026-02-09 17:53:40 +00:00
|
|
|
NavigationView {
|
|
|
|
|
ZStack(alignment: .bottomTrailing) {
|
2026-02-10 02:22:41 +00:00
|
|
|
TaskGroupListView()
|
2026-02-08 18:01:45 +01:00
|
|
|
|
2026-02-09 17:53:40 +00:00
|
|
|
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)
|
2026-02-08 18:01:45 +01:00
|
|
|
}
|
2026-02-09 17:53:40 +00:00
|
|
|
.navigationTitle("Todos")
|
|
|
|
|
}
|
|
|
|
|
.sheet(isPresented: $viewModel.newTaskShown) {
|
|
|
|
|
NewTaskView()
|
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()
|
|
|
|
|
}
|