Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Fix #8236: Adding export fail case and alert for success #8315

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class BookmarksViewController: SiteTableViewController, ToolbarUrlActionsProtoco
private var bookmarksSearchQuery = ""
private lazy var noSearchResultOverlayView = EmptyStateOverlayView(
overlayDetails: EmptyOverlayStateDetails(title: Strings.noSearchResultsfound))

private var bookmarksExportSuccessful = false

// MARK: Lifecycle

Expand Down Expand Up @@ -812,6 +814,17 @@ extension BookmarksViewController: UIDocumentPickerDelegate, UIDocumentInteracti
try? FileManager.default.removeItem(at: url)
}
self.documentInteractionController = nil

if bookmarksExportSuccessful {
bookmarksExportSuccessful = false

let alert = UIAlertController(
title: Strings.Sync.bookmarksImportExportPopupTitle,
message: Strings.Sync.bookmarksExportPopupSuccessMessage,
preferredStyle: .alert)
alert.addAction(UIAlertAction(title: Strings.OKString, style: .default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}

func documentInteractionControllerDidDismissOpenInMenu(_ controller: UIDocumentInteractionController) {
Expand All @@ -835,7 +848,7 @@ extension BookmarksViewController {
self.isLoading = false

let alert = UIAlertController(
title: Strings.Sync.bookmarksImportPopupErrorTitle,
title: Strings.Sync.bookmarksImportExportPopupTitle,
message: success ? Strings.Sync.bookmarksImportPopupSuccessMessage : Strings.Sync.bookmarksImportPopupFailureMessage,
preferredStyle: .alert)
alert.addAction(UIAlertAction(title: Strings.OKString, style: .default, handler: nil))
Expand All @@ -850,16 +863,27 @@ extension BookmarksViewController {
guard let self = self else { return }

self.isLoading = false

// Controller must be retained otherwise `AirDrop` and other sharing options will fail!
self.documentInteractionController = UIDocumentInteractionController(url: url)
guard let vc = self.documentInteractionController else { return }
vc.uti = UTType.html.identifier
vc.name = "Bookmarks.html"
vc.delegate = self

guard let importExportButton = self.importExportButton else { return }
vc.presentOptionsMenu(from: importExportButton, animated: true)

if success {
self.bookmarksExportSuccessful = true

// Controller must be retained otherwise `AirDrop` and other sharing options will fail!
self.documentInteractionController = UIDocumentInteractionController(url: url)
guard let vc = self.documentInteractionController else { return }
vc.uti = UTType.html.identifier
vc.name = "Bookmarks.html"
vc.delegate = self

guard let importExportButton = self.importExportButton else { return }
vc.presentOptionsMenu(from: importExportButton, animated: true)
} else {
let alert = UIAlertController(
title: Strings.Sync.bookmarksImportExportPopupTitle,
message: Strings.Sync.bookmarksExportPopupFailureMessage,
preferredStyle: .alert)
alert.addAction(UIAlertAction(title: Strings.OKString, style: .default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
}
}

Expand Down
10 changes: 9 additions & 1 deletion Sources/BraveStrings/BraveStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3227,14 +3227,22 @@ extension Strings {
NSLocalizedString("sync.syncV1DeprecationText", tableName: "BraveShared", bundle: .module,
value: "A new Brave Sync is coming and will affect your setup. Get ready for the upgrade.",
comment: "Text that informs a user about Brave Sync service deprecation.")
public static let bookmarksImportPopupErrorTitle =
public static let bookmarksImportExportPopupTitle =
NSLocalizedString("sync.bookmarksImportPopupErrorTitle", tableName: "BraveShared", bundle: .module,
value: "Bookmarks",
comment: "Title of the bookmark import popup.")
public static let bookmarksImportPopupSuccessMessage =
NSLocalizedString("sync.bookmarksImportPopupSuccessMessage", tableName: "BraveShared", bundle: .module,
value: "Bookmarks Imported Successfully",
comment: "Message of the popup if bookmark import succeeds.")
public static let bookmarksExportPopupSuccessMessage =
NSLocalizedString("sync.bookmarksExportPopupSuccessMessage", tableName: "BraveShared", bundle: .module,
value: "Bookmarks Exported Successfully",
comment: "Message of the popup if bookmark export succeeds.")
public static let bookmarksExportPopupFailureMessage =
NSLocalizedString("sync.bookmarksIExportPopupFailureMessage", tableName: "BraveShared", bundle: .module,
value: "Bookmark Export Failed",
comment: "Message of the popup if bookmark export fails.")
public static let bookmarksImportPopupFailureMessage =
NSLocalizedString("sync.bookmarksImportPopupFailureMessage", tableName: "BraveShared", bundle: .module,
value: "Bookmark Import Failed",
Expand Down