Skip to content

Commit

Permalink
Merge pull request #1631 from Automattic/charlie/1312/validate-tag-de…
Browse files Browse the repository at this point in the history
…lete

Validate deleting tag before completing
  • Loading branch information
charliescheer authored Aug 12, 2024
2 parents feee2cd + 35b582f commit ad38f67
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Simplenote/TagListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,13 @@ extension TagListViewController: TagListViewCellDelegate {
preferredStyle: .actionSheet)

alertController.addDestructiveActionWithTitle(Localization.TagDeletionConfirmation.confirmationButton) { (_) in
guard self.verifyTagIsAtIndexPath(tag, at: indexPath) else {
self.present(UIAlertController.dismissableAlert(
title: Localization.tagDeleteFailedTitle,
message: Localization.tagDeleteFailedMessage), animated: true)
return
}

switch source {
case .accessory:
SPTracker.trackTagRowDeleted()
Expand All @@ -519,6 +526,17 @@ extension TagListViewController: TagListViewCellDelegate {

present(alertController, animated: true, completion: nil)
}

private func verifyTagIsAtIndexPath(_ tagToRemove: Tag, at indexPath: IndexPath) -> Bool {
// REF: https://github.com/Automattic/simplenote-ios/issues/1312
// If you initiate deleting a tag and the tag is deleted before you confirm then another tag is deleted
// This method confirms the selected tag is the same as the tag at index path before removing.
guard let tagAtIndexPath = tag(at: indexPath) else {
return false
}

return tagToRemove.simperiumKey == tagAtIndexPath.simperiumKey
}
}

// MARK: - Helper Methods
Expand Down Expand Up @@ -888,6 +906,9 @@ private struct Localization {
static let tags = NSLocalizedString("Tags", comment: "Tags List Header")
static let untaggedNotes = NSLocalizedString("Untagged Notes", comment: "Allows selecting notes with no tags")

static let tagDeleteFailedTitle = NSLocalizedString("Could not delete tag", comment: "Notifies user tag delete failed")
static let tagDeleteFailedMessage = NSLocalizedString("Please try again", comment: "Encourages trying delete again")

struct TagDeletionConfirmation {
static func title(with tagName: String) -> String {
let template = NSLocalizedString("Are you sure you want to delete \"%1$@\"?", comment: "Title of deletion confirmation message for a tag. Parameters: %1$@ - tag name")
Expand Down

0 comments on commit ad38f67

Please sign in to comment.