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:
2026-02-12 01:21:19 +00:00
committed by javier
parent bbd7ec264b
commit 52376695a4
11 changed files with 355 additions and 47 deletions
+11 -11
View File
@@ -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
}
}