Skip to content

Commit

Permalink
✨ Remove empty tasks when cell loses focus
Browse files Browse the repository at this point in the history
This resolves #65

Signed-off-by: Peter Friese <peter@peterfriese.de>
  • Loading branch information
peterfriese committed Nov 1, 2021
1 parent fbcc56f commit 0dd0b72
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions code/frontend/MakeItSo/Shared/Extensions/View+Focus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import SwiftUI

/// Used to manage focus in a `List` view
enum Focusable: Hashable {
case none
case row(id: String)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ class TasksListViewModel: ObservableObject {
// if any row is focused, insert the new task after the focused row
if case .row(let id) = focusedTask {
if let index = tasks.firstIndex(where: { $0.id == id } ) {

// If the currently selected task is empty, unfocus it.
// This will kick off the pipeline that removes empty tasks.
let currentTask = tasks[index]
guard !currentTask.title.isEmpty else {
focusedTask = Focusable.none
return
}

tasks.insert(newTask, at: index + 1)
}
}
Expand Down

0 comments on commit 0dd0b72

Please sign in to comment.