Skip to content

Commit

Permalink
Improved error message actions
Browse files Browse the repository at this point in the history
  • Loading branch information
michalrentka committed Aug 21, 2024
1 parent 1d2b98f commit 52c87a3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Zotero/Assets/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
"back" = "Back";
"forward" = "Forward";
"go_to_settings" = "Go to Settings";
"close_without_saving" = "Close without saving";
"stay" = "Stay";

"beta_wipe_title" = "Resync Required";
"beta_wipe_message" = "Due to a beta update, your data must be redownloaded from zotero.org.";
Expand Down
4 changes: 4 additions & 0 deletions Zotero/Extensions/Localizable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ internal enum L10n {
/// Created by Michal Rentka on 21/04/2020.
/// Copyright © 2020 Corporation for Digital Scholarship. All rights reserved.
internal static let close = L10n.tr("Localizable", "close", fallback: "Close")
/// Close without saving
internal static let closeWithoutSaving = L10n.tr("Localizable", "close_without_saving", fallback: "Close without saving")
/// Copy
internal static let copy = L10n.tr("Localizable", "copy", fallback: "Copy")
/// Create
Expand Down Expand Up @@ -120,6 +122,8 @@ internal enum L10n {
internal static let share = L10n.tr("Localizable", "share", fallback: "Share")
/// Size
internal static let size = L10n.tr("Localizable", "size", fallback: "Size")
/// Stay
internal static let stay = L10n.tr("Localizable", "stay", fallback: "Stay")
/// Support and Feedback
internal static let supportFeedback = L10n.tr("Localizable", "support_feedback", fallback: "Support and Feedback")
/// Title
Expand Down
13 changes: 10 additions & 3 deletions Zotero/Scenes/General/NoteEditorCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import CocoaLumberjackSwift
protocol NoteEditorCoordinatorDelegate: AnyObject {
func show(url: URL)
func showTagPicker(libraryId: LibraryIdentifier, selected: Set<String>, picked: @escaping ([Tag]) -> Void)
func show(error: Error)
func show(error: Error, isClosing: Bool)
}

final class NoteEditorCoordinator: NSObject, Coordinator {
Expand Down Expand Up @@ -100,9 +100,16 @@ extension NoteEditorCoordinator: NoteEditorCoordinatorDelegate {
detailCoordinator.show(url: url)
}

func show(error: any Error) {
func show(error: any Error, isClosing: Bool) {
let controller = UIAlertController(title: L10n.error, message: error.localizedDescription, preferredStyle: .alert)
controller.addAction(UIAlertAction(title: L10n.ok, style: .cancel))
if !isClosing {
controller.addAction(UIAlertAction(title: L10n.ok, style: .cancel))
} else {
controller.addAction(UIAlertAction(title: L10n.stay, style: .cancel))
controller.addAction(UIAlertAction(title: L10n.closeWithoutSaving, style: .destructive, handler: { [weak self] _ in
self?.navigationController?.dismiss(animated: true)
}))
}
navigationController?.present(controller, animated: true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,12 @@ struct NoteEditorActionHandler: ViewModelActionHandler, BackgroundDbProcessingAc
func store(error: Swift.Error, key: String) {
update(viewModel: viewModel) { state in
state.error = error
state.isClosing = false
state.changes = [.saved, .closing]
if !state.isClosing {
state.changes = .saved
} else {
state.isClosing = false
state.changes = [.saved, .closing]
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion Zotero/Scenes/General/Views/NoteEditorViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ final class NoteEditorViewController: UIViewController {
}

if let error = state.error {
coordinatorDelegate?.show(error: error)
coordinatorDelegate?.show(error: error, isClosing: state.changes.contains(.closing))
}

func debounceSave() {
Expand Down

0 comments on commit 52c87a3

Please sign in to comment.