Skip to content

Commit

Permalink
Use New Tab Page implementation without customization features (#3453)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/72649045549333/1208547223289955/f
Tech Design URL:
CC:

**Description**:

Uses `NewTabPageController` as a home controller, but removes new tab
page customization capabilities based on `newTabPageSections` feature
flag state. Existing features of Home Screen should remain unchanged.

Summary of changes done in this PR:
* `SimpleNewTabPageView` now serving as a view for new tab page without
customization features. Created based on the fully featured
`NewTabPageView`.
* Favorites placeholders and add button are not visible when
customization flag is disabled.
* Report action is not added to the browsing menu when link is missing.
This prevents showing option which performs no action in case menu is
shown on NTP. (cc @afterxleep)
* Favorites data source adapter is listening for display mode changes
and updates favorites accordingly.
* Current (old) Dax Onboarding is integrated with the New Tab Page. (cc
@alessandroboron)

**Steps to test this PR**:

#### Dax onboarding
1. Install fresh app
2. Go through onboarding, make sure Dax dialogs are shown properly on
empty tab.

#### Basic functionality
1. Make sure NTP flag is disabled in debug menu.
3. Without favorites, Dax logo should be visible.
4. Add some favorites.
5. It should be possible to long press to edit/remove and drag and drop
to reorder.

#### Toolbar menu items
1. Check toolbar displays bookmarks icon when NTP sections flag
disabled.
2. Enable NTP sections flag in debug menu.
3. Reopen new tab page
4. Ensure browsing menu with shortcuts is available.

#### Sync
1. Enable sync on two devices.
2. Verify updates for favorites are visible.

**Definition of Done (Internal Only)**:

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

**Copy Testing**:

* [x] Use of correct apostrophes in new copy, ie `’` rather than `'`

**Orientation Testing**:

* [x] Portrait
* [x] Landscape

**Device Testing**:

* [ ] iPhone SE (1st Gen)
* [x] iPhone 8
* [ ] iPhone X
* [x] iPhone 14 Pro
* [ ] iPad

**OS Testing**:

* [x] iOS 15
* [ ] iOS 16
* [x] iOS 17

**Theme Testing**:

* [x] Light theme
* [x] Dark theme

---
###### Internal references:
[Software Engineering
Expectations](https://app.asana.com/0/59792373528535/199064865822552)
[Technical Design
Template](https://app.asana.com/0/59792373528535/184709971311943)
  • Loading branch information
dus7 authored Oct 23, 2024
1 parent 2bab26b commit ec52eaa
Show file tree
Hide file tree
Showing 19 changed files with 622 additions and 192 deletions.
24 changes: 16 additions & 8 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@
560E990F2BEE2CB800507CE0 /* SyncErrorMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 560E990E2BEE2CB800507CE0 /* SyncErrorMessage.swift */; };
564DE4532C3ED1B700D23241 /* NewTabDaxDialogFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564DE4522C3ED1B700D23241 /* NewTabDaxDialogFactory.swift */; };
564DE4552C3EDEF200D23241 /* ContextualOnboardingNewTabDialogFactoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564DE4542C3EDEF200D23241 /* ContextualOnboardingNewTabDialogFactoryTests.swift */; };
564DE4572C4150E600D23241 /* HomeViewControllerDaxDialogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564DE4562C4150E600D23241 /* HomeViewControllerDaxDialogTests.swift */; };
564DE4572C4150E600D23241 /* NewTabPageControllerDaxDialogTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564DE4562C4150E600D23241 /* NewTabPageControllerDaxDialogTests.swift */; };
564DE45A2C450BE600D23241 /* DaxDialogsNewTabTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564DE4592C450BE600D23241 /* DaxDialogsNewTabTests.swift */; };
564DE45E2C45218500D23241 /* OnboardingNavigationDelegateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564DE45D2C45218500D23241 /* OnboardingNavigationDelegateTests.swift */; };
564DE4602C4544CA00D23241 /* HomePageDependencies.swift in Sources */ = {isa = PBXBuildFile; fileRef = 564DE45F2C4544CA00D23241 /* HomePageDependencies.swift */; };
Expand Down Expand Up @@ -306,7 +306,9 @@
6F3537A42C4AC140009F8717 /* NewTabPageDaxLogoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F3537A32C4AC140009F8717 /* NewTabPageDaxLogoView.swift */; };
6F40D15B2C34423800BF22F0 /* HomePageDisplayDailyPixelBucket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F40D15A2C34423800BF22F0 /* HomePageDisplayDailyPixelBucket.swift */; };
6F40D15E2C34436500BF22F0 /* HomePageDisplayDailyPixelBucketTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F40D15C2C34436200BF22F0 /* HomePageDisplayDailyPixelBucketTests.swift */; };
6F5041C92CC11A5100989E48 /* SimpleNewTabPageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F5041C82CC11A5100989E48 /* SimpleNewTabPageView.swift */; };
6F5345AF2C53F2DE00424A43 /* NewTabPageSettingsPersistentStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F5345AE2C53F2DE00424A43 /* NewTabPageSettingsPersistentStorage.swift */; };
6F5AA3EF2CC1588400685CB4 /* FavoritesListInteractingAdapterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F5AA3EE2CC1588400685CB4 /* FavoritesListInteractingAdapterTests.swift */; };
6F5CC0812C2AFFE400AFC840 /* ToggleExpandButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F5CC0802C2AFFE400AFC840 /* ToggleExpandButtonStyle.swift */; };
6F64AA532C47E92600CF4489 /* FavoritesFaviconLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F64AA522C47E92600CF4489 /* FavoritesFaviconLoader.swift */; };
6F64AA592C4818D700CF4489 /* NewTabPageShortcut.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F64AA582C4818D700CF4489 /* NewTabPageShortcut.swift */; };
Expand Down Expand Up @@ -361,7 +363,7 @@
6FE127462C2054A900EB5724 /* NewTabPageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FE127452C2054A900EB5724 /* NewTabPageViewController.swift */; };
6FE1274B2C20943500EB5724 /* ShortcutItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FE1274A2C20943500EB5724 /* ShortcutItemView.swift */; };
6FEC0B852C999352006B4F6E /* FavoriteItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FEC0B842C999352006B4F6E /* FavoriteItem.swift */; };
6FEC0B882C999961006B4F6E /* FavoriteDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FEC0B872C999961006B4F6E /* FavoriteDataSource.swift */; };
6FEC0B882C999961006B4F6E /* FavoritesListInteractingAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FEC0B872C999961006B4F6E /* FavoritesListInteractingAdapter.swift */; };
6FF915822B88E07A0042AC87 /* AdAttributionFetcherTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FF915802B88E0750042AC87 /* AdAttributionFetcherTests.swift */; };
7BC571202BDBB877003B0CCE /* VPNActivationDateStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BC5711F2BDBB877003B0CCE /* VPNActivationDateStore.swift */; };
7BC571212BDBB977003B0CCE /* VPNActivationDateStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BC5711F2BDBB877003B0CCE /* VPNActivationDateStore.swift */; };
Expand Down Expand Up @@ -1551,7 +1553,7 @@
560E990E2BEE2CB800507CE0 /* SyncErrorMessage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SyncErrorMessage.swift; sourceTree = "<group>"; };
564DE4522C3ED1B700D23241 /* NewTabDaxDialogFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabDaxDialogFactory.swift; sourceTree = "<group>"; };
564DE4542C3EDEF200D23241 /* ContextualOnboardingNewTabDialogFactoryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContextualOnboardingNewTabDialogFactoryTests.swift; sourceTree = "<group>"; };
564DE4562C4150E600D23241 /* HomeViewControllerDaxDialogTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeViewControllerDaxDialogTests.swift; sourceTree = "<group>"; };
564DE4562C4150E600D23241 /* NewTabPageControllerDaxDialogTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPageControllerDaxDialogTests.swift; sourceTree = "<group>"; };
564DE4592C450BE600D23241 /* DaxDialogsNewTabTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DaxDialogsNewTabTests.swift; sourceTree = "<group>"; };
564DE45D2C45218500D23241 /* OnboardingNavigationDelegateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingNavigationDelegateTests.swift; sourceTree = "<group>"; };
564DE45F2C4544CA00D23241 /* HomePageDependencies.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomePageDependencies.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1589,7 +1591,9 @@
6F3537A32C4AC140009F8717 /* NewTabPageDaxLogoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPageDaxLogoView.swift; sourceTree = "<group>"; };
6F40D15A2C34423800BF22F0 /* HomePageDisplayDailyPixelBucket.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomePageDisplayDailyPixelBucket.swift; sourceTree = "<group>"; };
6F40D15C2C34436200BF22F0 /* HomePageDisplayDailyPixelBucketTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomePageDisplayDailyPixelBucketTests.swift; sourceTree = "<group>"; };
6F5041C82CC11A5100989E48 /* SimpleNewTabPageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleNewTabPageView.swift; sourceTree = "<group>"; };
6F5345AE2C53F2DE00424A43 /* NewTabPageSettingsPersistentStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPageSettingsPersistentStorage.swift; sourceTree = "<group>"; };
6F5AA3EE2CC1588400685CB4 /* FavoritesListInteractingAdapterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoritesListInteractingAdapterTests.swift; sourceTree = "<group>"; };
6F5CC0802C2AFFE400AFC840 /* ToggleExpandButtonStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToggleExpandButtonStyle.swift; sourceTree = "<group>"; };
6F64AA522C47E92600CF4489 /* FavoritesFaviconLoader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoritesFaviconLoader.swift; sourceTree = "<group>"; };
6F64AA582C4818D700CF4489 /* NewTabPageShortcut.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPageShortcut.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1645,7 +1649,7 @@
6FE127452C2054A900EB5724 /* NewTabPageViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPageViewController.swift; sourceTree = "<group>"; };
6FE1274A2C20943500EB5724 /* ShortcutItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShortcutItemView.swift; sourceTree = "<group>"; };
6FEC0B842C999352006B4F6E /* FavoriteItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoriteItem.swift; sourceTree = "<group>"; };
6FEC0B872C999961006B4F6E /* FavoriteDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoriteDataSource.swift; sourceTree = "<group>"; };
6FEC0B872C999961006B4F6E /* FavoritesListInteractingAdapter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoritesListInteractingAdapter.swift; sourceTree = "<group>"; };
6FF915802B88E0750042AC87 /* AdAttributionFetcherTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdAttributionFetcherTests.swift; sourceTree = "<group>"; };
7BC5711F2BDBB877003B0CCE /* VPNActivationDateStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VPNActivationDateStore.swift; sourceTree = "<group>"; };
83004E7F2193BB8200DA013C /* WKNavigationExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WKNavigationExtension.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3852,8 +3856,9 @@
6F7FB8DF2C660B1A00867DA7 /* NewTabPageFavoritesModelTests.swift */,
6F7FB8E42C66158D00867DA7 /* NewTabPageShortcutsSettingsModelTests.swift */,
6F7FB8E62C66197E00867DA7 /* NewTabPageSectionsSettingsModelTests.swift */,
564DE4562C4150E600D23241 /* HomeViewControllerDaxDialogTests.swift */,
564DE4562C4150E600D23241 /* NewTabPageControllerDaxDialogTests.swift */,
6FABAA682C6116FD003762EC /* NewTabPageShortcutsSettingsStorageTests.swift */,
6F5AA3EE2CC1588400685CB4 /* FavoritesListInteractingAdapterTests.swift */,
);
name = NewTabPage;
sourceTree = "<group>";
Expand Down Expand Up @@ -3907,7 +3912,7 @@
6FD3F8122C3EFDA200DA5797 /* FavoritesPreviewDataSource.swift */,
6FA3438E2C3D3BC300470677 /* Favorite.swift */,
6FEC0B842C999352006B4F6E /* FavoriteItem.swift */,
6FEC0B872C999961006B4F6E /* FavoriteDataSource.swift */,
6FEC0B872C999961006B4F6E /* FavoritesListInteractingAdapter.swift */,
);
name = Model;
sourceTree = "<group>";
Expand Down Expand Up @@ -3958,6 +3963,7 @@
6F03CAF82C32C3AA004179A8 /* Messages */,
6FE127372C20492500EB5724 /* NewTabPage.swift */,
6FD8E51F2C5BA23200345670 /* NewTabPageViewModel.swift */,
6F5041C82CC11A5100989E48 /* SimpleNewTabPageView.swift */,
6FE127392C204BD000EB5724 /* NewTabPageView.swift */,
6FE127452C2054A900EB5724 /* NewTabPageViewController.swift */,
6FD3F8182C41252900DA5797 /* NewTabPageControllerDelegate.swift */,
Expand Down Expand Up @@ -7462,6 +7468,7 @@
C185ED612BD4329700BAE9DC /* ImportPasswordsStatusHandler.swift in Sources */,
CB9B8739278C8E72001F4906 /* WidgetEducationViewController.swift in Sources */,
F4D9C4FA25117A0F00814B71 /* HomeMessageStorage.swift in Sources */,
6F5041C92CC11A5100989E48 /* SimpleNewTabPageView.swift in Sources */,
D69FBF762B28BE3600B505F1 /* SettingsSubscriptionView.swift in Sources */,
D664C7CC2B289AA200CBFA76 /* SubscriptionPagesUserScript.swift in Sources */,
AA3D854523D9942200788410 /* AppIconSettingsViewController.swift in Sources */,
Expand Down Expand Up @@ -7859,7 +7866,7 @@
1E4DCF4627B6A33600961E25 /* DownloadsListViewModel.swift in Sources */,
37C696772C4957940073E131 /* RemoteMessagingDebugViewController.swift in Sources */,
31860A5B2C57ED2D005561F5 /* DuckPlayerStorage.swift in Sources */,
6FEC0B882C999961006B4F6E /* FavoriteDataSource.swift in Sources */,
6FEC0B882C999961006B4F6E /* FavoritesListInteractingAdapter.swift in Sources */,
F4F6DFB626E6B71300ED7E12 /* BookmarkFoldersTableViewController.swift in Sources */,
8586A11024CCCD040049720E /* TabsBarViewController.swift in Sources */,
6FEC0B852C999352006B4F6E /* FavoriteItem.swift in Sources */,
Expand Down Expand Up @@ -7915,7 +7922,7 @@
98DA35C4268CC81E00159906 /* DomainMatchingReportTests.swift in Sources */,
8590CB632684F10F0089F6BF /* ContentBlockerProtectionStoreTests.swift in Sources */,
83EDCC411F86B89C005CDFCD /* StatisticsLoaderTests.swift in Sources */,
564DE4572C4150E600D23241 /* HomeViewControllerDaxDialogTests.swift in Sources */,
564DE4572C4150E600D23241 /* NewTabPageControllerDaxDialogTests.swift in Sources */,
C14882E327F20D9A00D59F0C /* BookmarksExporterTests.swift in Sources */,
85C29708247BDD060063A335 /* DaxDialogsBrowsingSpecTests.swift in Sources */,
9FE05CF12C36468A00D9046B /* OnboardingPixelReporterTests.swift in Sources */,
Expand Down Expand Up @@ -8026,6 +8033,7 @@
C14882EA27F20DD000D59F0C /* MockBookmarksCoreDataStorage.swift in Sources */,
1E05D1DB29C47B3300BF9A1F /* DailyPixelTests.swift in Sources */,
564DE4552C3EDEF200D23241 /* ContextualOnboardingNewTabDialogFactoryTests.swift in Sources */,
6F5AA3EF2CC1588400685CB4 /* FavoritesListInteractingAdapterTests.swift in Sources */,
981FED7422046017008488D7 /* AutoClearTests.swift in Sources */,
98DDF9F322C4029D00DE38DB /* InitHelpers.swift in Sources */,
B6AD9E3628D4510A0019CDE9 /* ContentBlockerRulesManagerMock.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/BrowsingMenu/BrowsingMenuAnimator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ final class BrowsingMenuAnimator: NSObject, UIViewControllerAnimatedTransitionin

fromViewController.view.isHidden = true

if toViewController.homeViewController != nil {
if toViewController.newTabPageViewController != nil {
toViewController.presentedMenuButton.setState(.bookmarksImage, animated: true)
} else {
toViewController.presentedMenuButton.setState(.menuImage, animated: true)
Expand Down
15 changes: 13 additions & 2 deletions DuckDuckGo/DaxDialogViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class DaxDialogViewController: UIViewController {
initCTA()
}
}

func calculateHeight() -> CGFloat {
guard let text = message ?? cta, !text.isEmpty else { return 370.0 }

Expand All @@ -59,7 +59,7 @@ class DaxDialogViewController: UIViewController {
let bottomMargin: CGFloat = 24.0
return iconHeight + topMargin + size.height + buttonHeight + bottomMargin
}

var onTapCta: (() -> Void)?

private var position: Int = 0
Expand Down Expand Up @@ -188,3 +188,14 @@ extension DaxDialogViewController {
}
}
}

extension DaxDialogViewController {
static func loadFromStoryboard() -> DaxDialogViewController {
let storyboard = UIStoryboard(name: "DaxOnboarding", bundle: Bundle.main)
guard let controller = storyboard.instantiateViewController(identifier: "DaxDialog") as? DaxDialogViewController else {
fatalError("Failed to instantiate DaxDialogViewController from storyboard")
}

return controller
}
}
6 changes: 5 additions & 1 deletion DuckDuckGo/FavoritesFaviconLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ actor FavoritesFaviconLoader: FavoritesFaviconLoading {
}

tasks[domain] = newTask
let value = await newTask.value
if value == nil {
tasks[domain] = nil
}

return await newTask.value
return value
}

nonisolated func existingFavicon(for favorite: Favorite, size: CGFloat) -> Favicon? {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// FavoriteDataSource.swift
// FavoritesListInteractingAdapter.swift
// DuckDuckGo
//
// Copyright © 2024 DuckDuckGo. All rights reserved.
Expand All @@ -24,12 +24,30 @@ import Bookmarks
final class FavoritesListInteractingAdapter: NewTabPageFavoriteDataSource {

let favoritesListInteracting: FavoritesListInteracting
let appSettings: AppSettings

init(favoritesListInteracting: FavoritesListInteracting) {
private var cancellables: Set<AnyCancellable> = []

private var displayModeSubject = PassthroughSubject<Void, Never>()

init(favoritesListInteracting: FavoritesListInteracting, appSettings: AppSettings = AppDependencyProvider.shared.appSettings) {
self.favoritesListInteracting = favoritesListInteracting
self.appSettings = appSettings
self.externalUpdates = favoritesListInteracting.externalUpdates.merge(with: displayModeSubject).eraseToAnyPublisher()

NotificationCenter.default.publisher(for: AppUserDefaults.Notifications.favoritesDisplayModeChange)
.receive(on: DispatchQueue.main)
.sink { [weak self] _ in
guard let self else {
return
}
favoritesListInteracting.favoritesDisplayMode = self.appSettings.favoritesDisplayMode
displayModeSubject.send()
}
.store(in: &cancellables)
}

var externalUpdates: AnyPublisher<Void, Never> { favoritesListInteracting.externalUpdates }
let externalUpdates: AnyPublisher<Void, Never>

var favorites: [Favorite] {
(try? favoritesListInteracting.favorites.map(Favorite.init)) ?? []
Expand Down
19 changes: 15 additions & 4 deletions DuckDuckGo/FavoritesViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,31 @@ class FavoritesViewModel: ObservableObject {
private let favoriteDataSource: NewTabPageFavoriteDataSource
private let pixelFiring: PixelFiring.Type
private let dailyPixelFiring: DailyPixelFiring.Type
private let isNewTabPageCustomizationEnabled: Bool

var isEmpty: Bool {
allFavorites.filter(\.isFavorite).isEmpty
}

init(favoriteDataSource: NewTabPageFavoriteDataSource,
init(isNewTabPageCustomizationEnabled: Bool = false,
favoriteDataSource: NewTabPageFavoriteDataSource,
faviconLoader: FavoritesFaviconLoading,
pixelFiring: PixelFiring.Type = Pixel.self,
dailyPixelFiring: DailyPixelFiring.Type = DailyPixel.self) {
self.favoriteDataSource = favoriteDataSource
self.pixelFiring = pixelFiring
self.dailyPixelFiring = dailyPixelFiring
self.isNewTabPageCustomizationEnabled = isNewTabPageCustomizationEnabled
self.isCollapsed = isNewTabPageCustomizationEnabled

self.faviconLoader = MissingFaviconWrapper(loader: faviconLoader, onFaviconMissing: { [weak self] in
guard let self else { return }

await MainActor.run {
self.faviconMissing()
}
})



favoriteDataSource.externalUpdates.sink { [weak self] _ in
self?.updateData()
}.store(in: &cancellables)
Expand All @@ -93,6 +97,10 @@ class FavoritesViewModel: ObservableObject {
}

func prefixedFavorites(for columnsCount: Int) -> FavoritesSlice {
guard isNewTabPageCustomizationEnabled else {
return .init(items: allFavorites, isCollapsible: false)
}

let hasFavorites = allFavorites.contains(where: \.isFavorite)
let maxCollapsedItemsCount = hasFavorites ? columnsCount * 2 : columnsCount
let isCollapsible = allFavorites.count > maxCollapsedItemsCount
Expand Down Expand Up @@ -170,7 +178,10 @@ class FavoritesViewModel: ObservableObject {
var allFavorites = favoriteDataSource.favorites.map {
FavoriteItem.favorite($0)
}
allFavorites.append(.addFavorite)

if isNewTabPageCustomizationEnabled {
allFavorites.append(.addFavorite)
}

self.allFavorites = allFavorites
}
Expand Down
Loading

0 comments on commit ec52eaa

Please sign in to comment.