diff --git a/App/Sources/View Models/TaskGroupListViewModel.swift b/App/Sources/View Models/TaskGroupListViewModel.swift index e420f98..7391a1e 100644 --- a/App/Sources/View Models/TaskGroupListViewModel.swift +++ b/App/Sources/View Models/TaskGroupListViewModel.swift @@ -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 diff --git a/App/Sources/View Models/TaskListViewModel.swift b/App/Sources/View Models/TaskListViewModel.swift index b4aae30..4514eff 100644 --- a/App/Sources/View Models/TaskListViewModel.swift +++ b/App/Sources/View Models/TaskListViewModel.swift @@ -85,52 +85,52 @@ extension TaskListView { // MARK: Methods - /// Deletes tasks at the specified indices. + /// Deletes todo tasks at the specified indices. /// /// This method removes tasks from the repository after a swipe-to-delete action. /// The deletion is performed through the repository, which handles /// persistence and triggers automatic UI updates. /// /// - Parameters: - /// - tasks: The current array of tasks. + /// - todos: The current array of todo tasks. /// - offsets: The index set of tasks to delete. /// - repository: The repository to perform the deletion. func delete( - _ tasks: [Todo], + _ todos: [Todo], at offsets: IndexSet, from repository: TodoRepository ) { for index in offsets { - repository.delete(tasks[index]) + repository.delete(todos[index]) } } - /// Reorders tasks after a drag and drop operation. + /// Reorders todo tasks after a drag and drop operation. /// /// This method is called when users drag and drop tasks to reorder them within a group. - /// It updates the `order` property of all tasks to reflect their new positions, ensuring + /// It updates the `order` property of all todo tasks to reflect their new positions, ensuring /// that the user's manual ordering preference is persisted. /// /// - Parameters: - /// - tasks: The current array of tasks before reordering. + /// - todos: The current array of todo tasks before reordering. /// - source: The index set of items being moved (typically a single index). /// - destination: The destination index where items should be inserted. /// - Note: This method should only be called for groups where `canReorder` is `true`. /// The view layer is responsible for only enabling drag and drop for applicable groups. /// - SeeAlso: ``TodoGroup/canReorder`` for determining which groups support reordering. func reorderTasks( - _ tasks: [Todo], + _ todos: [Todo], from source: IndexSet, to destination: Int ) { - var updatedTasks = tasks + var todosUpdated = todos - updatedTasks.move( + todosUpdated.move( fromOffsets: source, toOffset: destination ) - for (index, task) in updatedTasks.enumerated() { + for (index, task) in todosUpdated.enumerated() { task.order = index } }