-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Add FXIOS-10928 [Bookmarks Evolution] Last Viewed Bookmarks Folder Persists Across App Sessions #24047
base: main
Are you sure you want to change the base?
Add FXIOS-10928 [Bookmarks Evolution] Last Viewed Bookmarks Folder Persists Across App Sessions #24047
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ import Foundation | |
import Shared | ||
import Storage | ||
|
||
import enum MozillaAppServices.VisitType | ||
import MozillaAppServices | ||
|
||
protocol LibraryCoordinatorDelegate: AnyObject, LibraryPanelDelegate, RecentlyClosedPanelDelegate { | ||
func didFinishLibrary(from coordinator: Coordinator) | ||
|
@@ -135,12 +135,55 @@ class LibraryCoordinator: BaseCoordinator, | |
if isBookmarkRefactorEnabled { | ||
(navigationController.topViewController as? BookmarksViewController)? | ||
.bookmarkCoordinatorDelegate = bookmarksCoordinator | ||
if let recentFolderGUID = profile.prefs.stringForKey(PrefsKeys.LastViewedBookmarkFolder) { | ||
CATransaction.begin() | ||
CATransaction.setDisableActions(true) | ||
|
||
populateBookmarksNavigationController(currentFolderGUID: recentFolderGUID, | ||
bookmarksCoordinator: bookmarksCoordinator) { | ||
CATransaction.commit() | ||
} | ||
} | ||
} else { | ||
(navigationController.topViewController as? LegacyBookmarksPanel)? | ||
.bookmarkCoordinatorDelegate = bookmarksCoordinator | ||
} | ||
} | ||
|
||
private func populateBookmarksNavigationController(currentFolderGUID: String, | ||
bookmarksCoordinator: BookmarksCoordinator, | ||
completion: @escaping () -> Void) { | ||
profile.places.getBookmarksTree(rootGUID: BookmarkRoots.MobileFolderGUID, | ||
lmarceau marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are going to need to account for potentially loading into one of the desktop folders, so we'll need to pass in
As you can see, the places db has no concept of the "Desktop Bookmarks" folder that, in the UI, parents the 3 desktop folders (
The first one, not so bad, we can live with that, the second one... well the library panel probably won't load. I haven't done much investigation into what a proper fix would look like, so I am not sure the level of effort, but if it is a lot, as a backup I think we can just avoid the really unhappy path and hardcode it such that if a user is restoring into the "Desktop Bookmarks" folder, we just load them back to the "mobile" folder. What do you think? |
||
recursive: true).uponQueue(.main) { result in | ||
guard let maybeBookmarkTreeRoot = result.successValue, | ||
let bookmarkTreeRoot = maybeBookmarkTreeRoot else { return } | ||
guard var path = self.findPathToFolder(targetGUID: currentFolderGUID, | ||
treeRootNode: bookmarkTreeRoot), | ||
!path.isEmpty else {return} | ||
path.removeFirst() | ||
path.forEach { el in | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, when this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, the behaviour is the same as if we were to close the library panel, and re-open it without restarting the app. From what I understood this was the behaviour we were trying to mimic. If we would like to have animations active I can do that as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without animation is good! Just wanted to confirm I understood properly, thank you! |
||
bookmarksCoordinator.start(fromGUID: el.guid, animated: false) | ||
} | ||
completion() | ||
} | ||
} | ||
|
||
private func findPathToFolder(targetGUID: String, treeRootNode: BookmarkNodeData) -> [BookmarkNodeData]? { | ||
guard let treeRootFolder = treeRootNode as? BookmarkFolderData else { return nil} | ||
guard targetGUID != treeRootFolder.guid else {return [treeRootNode]} | ||
var path: [BookmarkNodeData]? | ||
|
||
guard let children = treeRootFolder.children else {return nil} | ||
for childNode in children { | ||
if let pathToFolder = findPathToFolder(targetGUID: targetGUID, treeRootNode: childNode) { | ||
path = pathToFolder | ||
} | ||
} | ||
guard path != nil else {return nil} | ||
path?.insert(treeRootNode, at: 0) | ||
return path | ||
} | ||
|
||
private func makeHistoryCoordinator(navigationController: UINavigationController) { | ||
guard !childCoordinators.contains(where: { $0 is HistoryCoordinator }) else { return } | ||
let router = DefaultRouter(navigationController: navigationController) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I understand why this is easier to be done here, but IMO we shouldn't have any business logic inside the coordinator. Coordinators role should be as simple as possible, and only hold navigation logic (no decision making apart from feature flags, and no database/network calls). Coordinator mostly creates VC, pass down dependencies, hold child coordinators, start flows, but they get told which navigation flow to start since they are not responsible per say of anything. Decision making normally falls into VC or other managers of some sort.
Now, what does this mean here? Well, IMO that some changes are needed 🙈 Maybe a way to keep this simple is to have a bookmarks state manager of some sort? The
LibraryViewController
could be responsible to fetch the path, then start the proper coordinator flow (through a parameter on thestart(panelType:)
function? Just trying to throw in some ideas, let me know if you have a better idea!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, I'll look into a different way of doing this that keeps the business logic out of the coordinators 😃 👍