Skip to content

Commit

Permalink
Fix add to favorites and open in new tabs action not working on manag…
Browse files Browse the repository at this point in the history
…er (#3467)

Task/Issue URL:
https://app.asana.com/0/1201048563534612/1208523846260390/f
Tech Design URL:
CC:

**Description**:
Fix add to favorites and open in new tabs action not working on the
bookmark manager when selecting multiple bookmarks.

**Steps to test this PR**:
1. Open Bookmarks Manager
2. Select multiple bookmarks
3. Right tap, select `Open in New Tabs`
4. All the bookmarks should be opened in new tabs
5. Select the bookmarks again (they should not be favorites), right-tap,
and select `Add to favorites`
6. The bookmarks should be added to favorites

**Definition of Done**:

* [x] Does this PR satisfy our [Definition of
Done](https://app.asana.com/0/1202500774821704/1207634633537039/f)?

—
###### Internal references:
[Pull Request Review
Checklist](https://app.asana.com/0/1202500774821704/1203764234894239/f)
[Software Engineering
Expectations](https://app.asana.com/0/59792373528535/199064865822552)
[Technical Design
Template](https://app.asana.com/0/59792373528535/184709971311943)
[Pull Request
Documentation](https://app.asana.com/0/1202500774821704/1204012835277482/f)
  • Loading branch information
jotaemepereira authored Nov 5, 2024
1 parent 0f91149 commit a8de1e0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
7 changes: 7 additions & 0 deletions DuckDuckGo/Bookmarks/Extensions/Bookmarks+Tab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ extension Tab {
}
}

@MainActor
static func with(contentsOf bookmarks: [Bookmark], burnerMode: BurnerMode) -> [Tab] {
bookmarks.compactMap { bookmark -> Tab? in
guard let url = bookmark.urlObject else { return nil }
return Tab(content: .url(url, source: .bookmark), shouldLoadInBackground: true, burnerMode: burnerMode)
}
}
}

extension TabCollection {
Expand Down
30 changes: 19 additions & 11 deletions DuckDuckGo/Bookmarks/Services/BookmarksContextMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,17 @@ extension BookmarksContextMenu: BookmarkMenuItemSelectors {
}

@objc func toggleBookmarkAsFavorite(_ sender: NSMenuItem) {
guard let bookmark = sender.representedObject as? Bookmark else {
if let bookmark = sender.representedObject as? Bookmark{
bookmark.isFavorite.toggle()
bookmarkManager.update(bookmark: bookmark)
} else if let bookmarks = sender.representedObject as? [Bookmark] {
bookmarks.forEach { bookmark in
bookmark.isFavorite.toggle()
bookmarkManager.update(bookmark: bookmark)
}
} else {
assertionFailure("Failed to cast menu represented object to Bookmark")
return
}

bookmark.isFavorite.toggle()
bookmarkManager.update(bookmark: bookmark)
}

@MainActor
Expand Down Expand Up @@ -424,16 +428,20 @@ extension BookmarksContextMenu: FolderMenuItemSelectors {

@MainActor
@objc func openInNewTabs(_ sender: NSMenuItem) {
guard let tabCollection = windowControllersManager.lastKeyMainWindowController?.mainViewController.tabCollectionViewModel,
let folder = sender.representedObject as? BookmarkFolder
else {
guard let tabCollection = windowControllersManager.lastKeyMainWindowController?.mainViewController.tabCollectionViewModel else {
assertionFailure("Cannot open all in new tabs")
return
}

let tabs = Tab.withContentOfBookmark(folder: folder, burnerMode: tabCollection.burnerMode)
tabCollection.append(tabs: tabs)
PixelExperiment.fireOnboardingBookmarkUsed5to7Pixel()
if let folder = sender.representedObject as? BookmarkFolder {
let tabs = Tab.withContentOfBookmark(folder: folder, burnerMode: tabCollection.burnerMode)
tabCollection.append(tabs: tabs)
PixelExperiment.fireOnboardingBookmarkUsed5to7Pixel()
} else if let bookmarks = sender.representedObject as? [Bookmark] {
let tabs = Tab.with(contentsOf: bookmarks, burnerMode: tabCollection.burnerMode)
tabCollection.append(tabs: tabs)
PixelExperiment.fireOnboardingBookmarkUsed5to7Pixel()
}
}

@MainActor
Expand Down

0 comments on commit a8de1e0

Please sign in to comment.