Skip to content

Commit

Permalink
Fix #4717 - Provide feedback when pinning a site (#6785)
Browse files Browse the repository at this point in the history
* Fix #4717 - Provide feedback when pinning a site from inside the Library panel

Display toast notification on the Library panel
Display toast notification on the Bookmarks panel
Display toast notification on the Website tab

* Change to remove

Co-authored-by: Vlad Dramaretskyi <vlad@Vlads-MacBook-Pro.local>
  • Loading branch information
dnarcese and Vlad Dramaretskyi committed Jun 24, 2020
1 parent 7ed0ddf commit c51aab1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
6 changes: 5 additions & 1 deletion Client/Frontend/Library/BookmarksPanel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,11 @@ extension BookmarksPanel: LibraryPanelContextMenu {
}

let pinTopSite = PhotonActionSheetItem(title: Strings.PinTopsiteActionTitle, iconString: "action_pin", handler: { _, _ in
_ = self.profile.history.addPinnedTopSite(site)
_ = self.profile.history.addPinnedTopSite(site).uponQueue(.main) { result in
if result.isSuccess {
SimpleToast().showAlertWithText(Strings.AppMenuAddPinToTopSitesConfirmMessage, bottomContainer: self.view)
}
}
})
actions.append(pinTopSite)

Expand Down
6 changes: 5 additions & 1 deletion Client/Frontend/Library/HistoryPanel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,11 @@ class HistoryPanel: SiteTableViewController, LibraryPanel {
}

func pinToTopSites(_ site: Site) {
_ = profile.history.addPinnedTopSite(site).value
_ = profile.history.addPinnedTopSite(site).uponQueue(.main) { result in
if result.isSuccess {
SimpleToast().showAlertWithText(Strings.AppMenuAddPinToTopSitesConfirmMessage, bottomContainer: self.view)
}
}
}

func navigateToRecentlyClosed() {
Expand Down
2 changes: 2 additions & 0 deletions Client/Frontend/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,8 @@ extension Strings {
public static let AppMenuAddBookmarkConfirmMessage = NSLocalizedString("Menu.AddBookmark.Confirm", value: "Bookmark Added", comment: "Toast displayed to the user after a bookmark has been added.")
public static let AppMenuTabSentConfirmMessage = NSLocalizedString("Menu.TabSent.Confirm", value: "Tab Sent", comment: "Toast displayed to the user after a tab has been sent successfully.")
public static let AppMenuRemoveBookmarkConfirmMessage = NSLocalizedString("Menu.RemoveBookmark.Confirm", value: "Bookmark Removed", comment: "Toast displayed to the user after a bookmark has been removed.")
public static let AppMenuAddPinToTopSitesConfirmMessage = NSLocalizedString("Menu.AddPin.Confirm", value: "Pinned To Top Sites", comment: "Toast displayed to the user after adding the item to the Top Sites.")
public static let AppMenuRemovePinFromTopSitesConfirmMessage = NSLocalizedString("Menu.RemovePin.Confirm", value: "Removed From Top Sites", comment: "Toast displayed to the user after removing the item from the Top Sites.")
public static let AppMenuAddToReadingListConfirmMessage = NSLocalizedString("Menu.AddToReadingList.Confirm", value: "Added To Reading List", comment: "Toast displayed to the user after adding the item to their reading list.")
public static let SendToDeviceTitle = NSLocalizedString("Send to Device", tableName: "3DTouchActions", comment: "Label for preview action on Tab Tray Tab to send the current tab to another device")
public static let PageActionMenuTitle = NSLocalizedString("Menu.PageActions.Title", value: "Page Actions", comment: "Label for title in page action menu.")
Expand Down
15 changes: 12 additions & 3 deletions Client/Frontend/Widgets/PhotonActionSheet/PageActionMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ enum ButtonToastAction {
case bookmarkPage
case removeBookmark
case copyUrl
case pinPage
case removePinPage
}

extension PhotonActionSheetProtocol {
Expand Down Expand Up @@ -97,9 +99,12 @@ extension PhotonActionSheetProtocol {
guard let site = val.successValue?.asArray().first?.flatMap({ $0 }) else {
return succeed()
}

return self.profile.history.addPinnedTopSite(site)
}.uponQueue(.main) { _ in }
}.uponQueue(.main) { result in
if result.isSuccess {
success(Strings.AppMenuAddPinToTopSitesConfirmMessage, .pinPage)
}
}
}

let removeTopSitesPin = PhotonActionSheetItem(title: Strings.RemovePinTopsiteActionTitle, iconString: "action_unpin") { _, _ in
Expand All @@ -111,7 +116,11 @@ extension PhotonActionSheetProtocol {
}

return self.profile.history.removeFromPinnedTopSites(site)
}.uponQueue(.main) { _ in }
}.uponQueue(.main) { result in
if result.isSuccess {
success(Strings.AppMenuRemovePinFromTopSitesConfirmMessage, .removePinPage)
}
}
}

let sendToDevice = PhotonActionSheetItem(title: Strings.SendToDeviceTitle, iconString: "menu-Send-to-Device") { _, _ in
Expand Down

0 comments on commit c51aab1

Please sign in to comment.