New task feature (#2)
This PR contains the work done to implement the **New Task** feature, and to integrate it into the main context view of the app. Reviewed-on: rock-n-code/todos-app#2 Co-authored-by: Javier Cicchelli <javier@rock-n-code.com> Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
This commit was merged in pull request #2.
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import SwiftData
|
||||
import SwiftUI
|
||||
|
||||
extension ContentView {
|
||||
|
||||
/// View model for managing the logic for the content view.
|
||||
///
|
||||
/// This observable class encapsulates the state and business logic for the main content view.
|
||||
/// It follows the MVVM pattern to separate presentation logic from the view layer.
|
||||
///
|
||||
/// The view model manages:
|
||||
/// - Presentation state for the new task view within a sheet.
|
||||
@Observable
|
||||
class ViewModel {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
/// Whether the new task view should be shown.
|
||||
var newTaskShown: Bool
|
||||
|
||||
// MARK: Initialization
|
||||
|
||||
/// Initializes a new view model instance with default values.
|
||||
///
|
||||
/// The view model is initialized with:
|
||||
/// - New task view hidden
|
||||
init() {
|
||||
newTaskShown = false
|
||||
}
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
/// Shows the new task view by setting the presentation state to true.
|
||||
func showNewTask() {
|
||||
newTaskShown = true
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user