Task edition improvements (#9)
This PR contains the work done to improve upon the editing experience on the **Task list item and the **New task** views. Reviewed-on: rock-n-code/todos-app#9 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 #9.
This commit is contained in:
@@ -9,8 +9,8 @@ extension TaskGroupListView {
|
||||
/// It follows the MVVM pattern to separate presentation logic from the view layer.
|
||||
///
|
||||
/// ## Responsibilities
|
||||
/// - Providing access to all task groups for iteration
|
||||
/// - Efficiently counting tasks per group using SwiftData fetch descriptors
|
||||
/// - Providing access to all todo task groups for iteration
|
||||
/// - Efficiently counting todo tasks per group using SwiftData fetch descriptors
|
||||
/// - Managing date calculations for group categorization
|
||||
@Observable
|
||||
final class ViewModel {
|
||||
@@ -38,46 +38,46 @@ extension TaskGroupListView {
|
||||
///
|
||||
/// This computed property provides access to all task group cases for iteration in the view.
|
||||
///
|
||||
/// - Returns: An array of all `TodoGroup` cases in a predetermined order.
|
||||
/// - Returns: An array of all the todo group cases in a predetermined order.
|
||||
var groups: [TodoGroup] {
|
||||
TodoGroup.allCases
|
||||
}
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
/// Calculates the number of tasks for a given task group from an in-memory collection.
|
||||
/// Calculates the number of todo tasks for a given todo group from an in-memory collection.
|
||||
///
|
||||
/// This method filters the provided tasks array to count only those tasks that belong
|
||||
/// to the specified group based on their due date and completion status. Tasks are
|
||||
/// This method filters the provided todo tasks array to count only those todo tasks that belong
|
||||
/// to the specified group based on their due date and completion status. Todo tasks are
|
||||
/// categorized as follows:
|
||||
///
|
||||
/// - **Completed**: Tasks with a non-nil `completed` date
|
||||
/// - **Overdue**: Incomplete tasks due before today
|
||||
/// - **Today**: Incomplete tasks due today (from start of day to end of day)
|
||||
/// - **Upcoming**: Incomplete tasks due tomorrow or later
|
||||
/// - **Completed**: Todo tasks with a non-nil `completed` date
|
||||
/// - **Overdue**: Incomplete todo tasks due before today
|
||||
/// - **Today**: Incomplete todo tasks due today (from start of day to end of day)
|
||||
/// - **Upcoming**: Incomplete todo tasks due tomorrow or later
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - tasks: The array of tasks to filter and count.
|
||||
/// - todos: The array of todo tasks to filter and count.
|
||||
/// - group: The task group to count tasks for.
|
||||
/// - Returns: The number of tasks in the specified group.
|
||||
func count(
|
||||
_ tasks: [Todo],
|
||||
_ todos: [Todo],
|
||||
for group: TodoGroup
|
||||
) -> Int {
|
||||
let today = calendar.startOfDay(for: .now)
|
||||
let tomorrow = calendar.date(byAdding: .day, value: 1, to: today) ?? .now
|
||||
|
||||
return tasks
|
||||
.filter { task in
|
||||
return todos
|
||||
.filter { todo in
|
||||
switch group {
|
||||
case .completed:
|
||||
task.completed != nil
|
||||
todo.completed != nil
|
||||
case .overdue:
|
||||
task.completed == nil && task.due < today
|
||||
todo.completed == nil && todo.due < today
|
||||
case .today:
|
||||
task.completed == nil && task.due >= today && task.due < tomorrow
|
||||
todo.completed == nil && todo.due >= today && todo.due < tomorrow
|
||||
case .upcoming:
|
||||
task.completed == nil && task.due >= tomorrow
|
||||
todo.completed == nil && todo.due >= tomorrow
|
||||
}
|
||||
}
|
||||
.count
|
||||
|
||||
Reference in New Issue
Block a user