Skip to content

Commit 0dd0b72

Browse files
committed
✨ Remove empty tasks when cell loses focus
This resolves #65 Signed-off-by: Peter Friese <peter@peterfriese.de>
1 parent fbcc56f commit 0dd0b72

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

code/frontend/MakeItSo/Shared/Extensions/View+Focus.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import SwiftUI
2121

2222
/// Used to manage focus in a `List` view
2323
enum Focusable: Hashable {
24+
case none
2425
case row(id: String)
2526
}
2627

code/frontend/MakeItSo/Shared/Features/TaskList/ViewModels/TasksListViewModel.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ class TasksListViewModel: ObservableObject {
8181
// if any row is focused, insert the new task after the focused row
8282
if case .row(let id) = focusedTask {
8383
if let index = tasks.firstIndex(where: { $0.id == id } ) {
84+
85+
// If the currently selected task is empty, unfocus it.
86+
// This will kick off the pipeline that removes empty tasks.
87+
let currentTask = tasks[index]
88+
guard !currentTask.title.isEmpty else {
89+
focusedTask = Focusable.none
90+
return
91+
}
92+
8493
tasks.insert(newTask, at: index + 1)
8594
}
8695
}

0 commit comments

Comments
 (0)