diff --git a/DuckDuckGo/Bookmarks/Model/BookmarkList.swift b/DuckDuckGo/Bookmarks/Model/BookmarkList.swift index 82b38ab675..24892af498 100644 --- a/DuckDuckGo/Bookmarks/Model/BookmarkList.swift +++ b/DuckDuckGo/Bookmarks/Model/BookmarkList.swift @@ -51,9 +51,7 @@ struct BookmarkList { } } - // Reverse the order of favorites, such that new favorites appear at the top. - // This will be improved later with the filtering/sorting additions. - self.favoriteBookmarkURLsOrdered = favoriteKeysOrdered.reversed() + self.favoriteBookmarkURLsOrdered = favoriteKeysOrdered self.allBookmarkURLsOrdered = keysOrdered self.itemsDict = itemsDict self.topLevelEntities = topLevelEntities @@ -65,7 +63,7 @@ struct BookmarkList { return } - allBookmarkURLsOrdered.insert(bookmark.url, at: 0) + allBookmarkURLsOrdered.append(bookmark.url) // .insert(bookmark.url, at: 0) itemsDict[bookmark.url] = bookmark } diff --git a/DuckDuckGo/Bookmarks/Services/BookmarkStore.swift b/DuckDuckGo/Bookmarks/Services/BookmarkStore.swift index f210f9df29..4a33351360 100644 --- a/DuckDuckGo/Bookmarks/Services/BookmarkStore.swift +++ b/DuckDuckGo/Bookmarks/Services/BookmarkStore.swift @@ -90,7 +90,7 @@ final class LocalBookmarkStore: BookmarkStore { fetchRequest = Bookmark.topLevelEntitiesFetchRequest() } - fetchRequest.sortDescriptors = [NSSortDescriptor(key: #keyPath(BookmarkManagedObject.dateAdded), ascending: false)] + fetchRequest.sortDescriptors = [NSSortDescriptor(key: #keyPath(BookmarkManagedObject.dateAdded), ascending: true)] fetchRequest.returnsObjectsAsFaults = false do { @@ -364,17 +364,6 @@ final class LocalBookmarkStore: BookmarkStore { let allFolders = try context.fetch(BookmarkFolder.bookmarkFoldersFetchRequest()) - if let otherBookmarks = bookmarks.topLevelFolders.otherBookmarks.children { - // Reverse the top level collection so that the order matches the imported bookmarks correctly. - let result = recursivelyCreateEntities(from: otherBookmarks.reversed(), - parent: nil, - existingBookmarkURLs: bookmarkURLs, - markBookmarksAsFavorite: false, - in: self.context) - - total += result - } - let existingFavoritesFolder = allFolders.first { ($0.titleEncrypted as? String) == UserText.bookmarkImportImportedFavorites } let favoritesFolder = existingFavoritesFolder ?? createFolder(titled: UserText.bookmarkImportImportedFavorites, in: self.context) @@ -388,6 +377,17 @@ final class LocalBookmarkStore: BookmarkStore { total += result } + if let otherBookmarks = bookmarks.topLevelFolders.otherBookmarks.children { + // Reverse the top level collection so that the order matches the imported bookmarks correctly. + let result = recursivelyCreateEntities(from: otherBookmarks, + parent: nil, + existingBookmarkURLs: bookmarkURLs, + markBookmarksAsFavorite: false, + in: self.context) + + total += result + } + try self.context.save() let bookmarkCountAfterImport = try context.count(for: Bookmark.bookmarksFetchRequest())