Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix add to favorites and open in new tabs action not working on manager #3467

Merged
merged 3 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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 withContentOfBookmark(bookmarks: [Bookmark], burnerMode: BurnerMode) -> [Tab] {
jotaemepereira marked this conversation as resolved.
Show resolved Hide resolved
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.withContentOfBookmark(bookmarks: bookmarks, burnerMode: tabCollection.burnerMode)
tabCollection.append(tabs: tabs)
PixelExperiment.fireOnboardingBookmarkUsed5to7Pixel()
}
}

@MainActor
Expand Down
Loading