Skip to content

Commit

Permalink
Add NewTabPageNextStepsCardsProvider to encapsulate ContinueSetUpMode…
Browse files Browse the repository at this point in the history
…l and AppearancePreferences
  • Loading branch information
ayoy committed Dec 11, 2024
1 parent c455988 commit 1d00999
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 18 deletions.
12 changes: 6 additions & 6 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1115,8 +1115,6 @@
372A0FED2B2379310033BF7F /* SyncMetricsEventsHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372A0FEB2B2379310033BF7F /* SyncMetricsEventsHandler.swift */; };
372BC2A12A4AFA47001D8FD5 /* SyncCredentialsAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372BC2A02A4AFA47001D8FD5 /* SyncCredentialsAdapter.swift */; };
372BC2A22A4AFA47001D8FD5 /* SyncCredentialsAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372BC2A02A4AFA47001D8FD5 /* SyncCredentialsAdapter.swift */; };
372D15E92D00F19500A11576 /* ContinueSetUpModel+NewTabPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372D15E82D00F18E00A11576 /* ContinueSetUpModel+NewTabPage.swift */; };
372D15EA2D00F19500A11576 /* ContinueSetUpModel+NewTabPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372D15E82D00F18E00A11576 /* ContinueSetUpModel+NewTabPage.swift */; };
372D15EC2D00FA1A00A11576 /* AppearancePreferences+NewTabPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372D15EB2D00FA1400A11576 /* AppearancePreferences+NewTabPage.swift */; };
372D15ED2D00FA1A00A11576 /* AppearancePreferences+NewTabPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 372D15EB2D00FA1400A11576 /* AppearancePreferences+NewTabPage.swift */; };
3739326529AE4B39009346AE /* DDGSync in Frameworks */ = {isa = PBXBuildFile; productRef = 3739326429AE4B39009346AE /* DDGSync */; };
Expand Down Expand Up @@ -1230,6 +1228,8 @@
37B11B3928095E6600CBB621 /* TabLazyLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37B11B3828095E6600CBB621 /* TabLazyLoader.swift */; };
37BA812D29B3CD690053F1A3 /* SyncUI in Frameworks */ = {isa = PBXBuildFile; productRef = 37BA812C29B3CD690053F1A3 /* SyncUI */; };
37BA812F29B3CD6E0053F1A3 /* SyncUI in Frameworks */ = {isa = PBXBuildFile; productRef = 37BA812E29B3CD6E0053F1A3 /* SyncUI */; };
37BE087A2D09C0F200C77B8E /* NewTabPageNextStepsCardsProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37BE08792D09C0EA00C77B8E /* NewTabPageNextStepsCardsProvider.swift */; };
37BE087B2D09C0F200C77B8E /* NewTabPageNextStepsCardsProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37BE08792D09C0EA00C77B8E /* NewTabPageNextStepsCardsProvider.swift */; };
37BF3F14286D8A6500BD9014 /* PinnedTabsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37BF3F13286D8A6500BD9014 /* PinnedTabsManager.swift */; };
37BF3F21286F0A7A00BD9014 /* PinnedTabsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37BF3F1E286F0A7A00BD9014 /* PinnedTabsViewModel.swift */; };
37BF3F22286F0A7A00BD9014 /* PinnedTabsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37BF3F1F286F0A7A00BD9014 /* PinnedTabsView.swift */; };
Expand Down Expand Up @@ -3646,7 +3646,6 @@
37219B3C2CC27DB300C9D7A8 /* NewTabPageSearchBoxExperimentTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPageSearchBoxExperimentTests.swift; sourceTree = "<group>"; };
372A0FEB2B2379310033BF7F /* SyncMetricsEventsHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SyncMetricsEventsHandler.swift; sourceTree = "<group>"; };
372BC2A02A4AFA47001D8FD5 /* SyncCredentialsAdapter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SyncCredentialsAdapter.swift; sourceTree = "<group>"; };
372D15E82D00F18E00A11576 /* ContinueSetUpModel+NewTabPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ContinueSetUpModel+NewTabPage.swift"; sourceTree = "<group>"; };
372D15EB2D00FA1400A11576 /* AppearancePreferences+NewTabPage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AppearancePreferences+NewTabPage.swift"; sourceTree = "<group>"; };
373A1AA7283ED1B900586521 /* BookmarkHTMLReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarkHTMLReader.swift; sourceTree = "<group>"; };
373A1AA9283ED86C00586521 /* BookmarksHTMLReaderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarksHTMLReaderTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3730,6 +3729,7 @@
37AFCE9127DB8CAD00471A10 /* PreferencesAboutView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesAboutView.swift; sourceTree = "<group>"; };
37B11B3828095E6600CBB621 /* TabLazyLoader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabLazyLoader.swift; sourceTree = "<group>"; };
37BA812B29B3CB8A0053F1A3 /* SyncUI */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = SyncUI; sourceTree = "<group>"; };
37BE08792D09C0EA00C77B8E /* NewTabPageNextStepsCardsProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewTabPageNextStepsCardsProvider.swift; sourceTree = "<group>"; };
37BF3F13286D8A6500BD9014 /* PinnedTabsManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PinnedTabsManager.swift; sourceTree = "<group>"; };
37BF3F1E286F0A7A00BD9014 /* PinnedTabsViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PinnedTabsViewModel.swift; sourceTree = "<group>"; };
37BF3F1F286F0A7A00BD9014 /* PinnedTabsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PinnedTabsView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -5830,10 +5830,10 @@
376788092CECCAD900F59D83 /* NewTabPage */ = {
isa = PBXGroup;
children = (
37BE08792D09C0EA00C77B8E /* NewTabPageNextStepsCardsProvider.swift */,
37E307B12D075B5E00599500 /* NewTabPagePrivacyStatsEventHandler.swift */,
374EFDF22D01C99700B30939 /* ActiveRemoteMessageModel+NewTabPage.swift */,
372D15EB2D00FA1400A11576 /* AppearancePreferences+NewTabPage.swift */,
372D15E82D00F18E00A11576 /* ContinueSetUpModel+NewTabPage.swift */,
3772BEDC2D019CDF0019B9EF /* DefaultsFavoritesActionHandler.swift */,
371BBC5D2D00CA3E008FA0C7 /* NewTabPageWebViewModel.swift */,
371BBC5A2D00C911008FA0C7 /* NewTabPageActionsManagerExtension.swift */,
Expand Down Expand Up @@ -11615,6 +11615,7 @@
1D4071AF2BD64267002D4537 /* DockCustomizer.swift in Sources */,
C153E7C32C8AD68D00B9BAD7 /* FreemiumDBPPromotionViewCoordinator.swift in Sources */,
4B41EDA42B1543B9001EEDF4 /* VPNPreferencesModel.swift in Sources */,
37BE087A2D09C0F200C77B8E /* NewTabPageNextStepsCardsProvider.swift in Sources */,
1E559BB22BBCA9F1002B4AF6 /* RedirectNavigationResponder.swift in Sources */,
3706FB6C293F65D500E42796 /* FaviconStore.swift in Sources */,
3706FB6D293F65D500E42796 /* SuggestionListCharacteristics.swift in Sources */,
Expand Down Expand Up @@ -12092,7 +12093,6 @@
B6C0BB6829AEFF8100AE8E3C /* BookmarkExtension.swift in Sources */,
B69A14FB2B4D705D00B9417D /* BookmarkFolderPicker.swift in Sources */,
3706FC6C293F65D500E42796 /* BookmarkViewModel.swift in Sources */,
372D15EA2D00F19500A11576 /* ContinueSetUpModel+NewTabPage.swift in Sources */,
3706FC6D293F65D500E42796 /* DaxSpeech.swift in Sources */,
CB63DECC2CDC0BBE0097986A /* PageRefreshMonitor.swift in Sources */,
3706FC6E293F65D500E42796 /* DuckURLSchemeHandler.swift in Sources */,
Expand Down Expand Up @@ -12901,6 +12901,7 @@
buildActionMask = 2147483647;
files = (
AAA0CC572539EBC90079BC96 /* FaviconUserScript.swift in Sources */,
37BE087B2D09C0F200C77B8E /* NewTabPageNextStepsCardsProvider.swift in Sources */,
3158B1532B0BF75700AF130C /* LoginItem+DataBrokerProtection.swift in Sources */,
1D2DC0082901679E008083A1 /* BWResponse.swift in Sources */,
AADCBF3A26F7C2CE00EF67A8 /* LottieAnimationCache.swift in Sources */,
Expand Down Expand Up @@ -13320,7 +13321,6 @@
3199AF792C80734A003AEBDC /* DuckPlayerOnboardingViewModel.swift in Sources */,
B6685E4229A61C470043D2EE /* DownloadsTabExtension.swift in Sources */,
4B8AC93B26B48ADF00879451 /* ASN1Parser.swift in Sources */,
372D15E92D00F19500A11576 /* ContinueSetUpModel+NewTabPage.swift in Sources */,
856C98DF257014BD00A22F1F /* FileDownloadManager.swift in Sources */,
4BB99CFF26FE191E001E4761 /* BookmarkImport.swift in Sources */,
B68503A7279141CD00893A05 /* KeySetDictionary.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ extension NewTabPageActionsManager {
self.init(scriptClients: [
NewTabPageConfigurationClient(sectionsVisibilityProvider: appearancePreferences),
NewTabPageRMFClient(remoteMessageProvider: activeRemoteMessageModel),
NewTabPageNextStepsCardsClient(model: HomePage.Models.ContinueSetUpModel(tabOpener: NewTabPageTabOpener())),
NewTabPageNextStepsCardsClient(model: NewTabPageNextStepsCardsProvider(continueSetUpModel: HomePage.Models.ContinueSetUpModel(tabOpener: NewTabPageTabOpener()))),
NewTabPageFavoritesClient(favoritesModel: favoritesModel, preferredFaviconSize: Int(Favicon.SizeCategory.medium.rawValue)),
NewTabPagePrivacyStatsClient(model: privacyStatsModel)
])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// ContinueSetUpModel+NewTabPage.swift
// NewTabPageNextStepsCardsProvider.swift
//
// Copyright © 2024 DuckDuckGo. All rights reserved.
//
Expand All @@ -22,26 +22,34 @@ import NewTabPage
import PixelKit
import UserScript

extension HomePage.Models.ContinueSetUpModel: NewTabPageNextStepsCardsProviding {
final class NewTabPageNextStepsCardsProvider: NewTabPageNextStepsCardsProviding {
let continueSetUpModel: HomePage.Models.ContinueSetUpModel
let appearancePreferences: AppearancePreferences

init(continueSetUpModel: HomePage.Models.ContinueSetUpModel, appearancePreferences: AppearancePreferences = .shared) {
self.continueSetUpModel = continueSetUpModel
self.appearancePreferences = appearancePreferences
}

var isViewExpanded: Bool {
get {
shouldShowAllFeatures
continueSetUpModel.shouldShowAllFeatures
}
set {
shouldShowAllFeatures = newValue
continueSetUpModel.shouldShowAllFeatures = newValue
}
}

var isViewExpandedPublisher: AnyPublisher<Bool, Never> {
shouldShowAllFeaturesPublisher.eraseToAnyPublisher()
continueSetUpModel.shouldShowAllFeaturesPublisher.eraseToAnyPublisher()
}

var cards: [NewTabPageNextStepsCardsClient.CardID] {
featuresMatrix.flatMap { $0.map(NewTabPageNextStepsCardsClient.CardID.init) }
continueSetUpModel.featuresMatrix.flatMap { $0.map(NewTabPageNextStepsCardsClient.CardID.init) }
}

var cardsPublisher: AnyPublisher<[NewTabPageNextStepsCardsClient.CardID], Never> {
$featuresMatrix.dropFirst().removeDuplicates()
continueSetUpModel.$featuresMatrix.dropFirst().removeDuplicates()
.map { matrix in
matrix.flatMap { $0.map(NewTabPageNextStepsCardsClient.CardID.init) }
}
Expand All @@ -50,19 +58,24 @@ extension HomePage.Models.ContinueSetUpModel: NewTabPageNextStepsCardsProviding

@MainActor
func handleAction(for card: NewTabPageNextStepsCardsClient.CardID) {
performAction(for: .init(card))
continueSetUpModel.performAction(for: .init(card))
}

@MainActor
func dismiss(_ card: NewTabPageNextStepsCardsClient.CardID) {
removeItem(for: .init(card))
continueSetUpModel.removeItem(for: .init(card))
}

@MainActor
func willDisplayCards(_ cards: [NewTabPageNextStepsCardsClient.CardID]) {
appearancePreferences.continueSetUpCardsViewDidAppear()
fireAddToDockPixelIfNeeded(cards)
}

private func fireAddToDockPixelIfNeeded(_ cards: [NewTabPageNextStepsCardsClient.CardID]) {
guard cards.contains(.addAppToDockMac) else {
return
}
continueSetUpCardsViewDidAppear()
PixelKit.fire(GeneralPixel.addToDockNewTabPageCardPresented,
frequency: .uniqueByName,
includeAppVersionParameter: false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ public final class NewTabPageNextStepsCardsClient: NewTabPageScriptClient {

willDisplayCardsPublisher
.sink { cards in
model.willDisplayCards(cards)
Task { @MainActor in
model.willDisplayCards(cards)
}
}
.store(in: &cancellables)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ public protocol NewTabPageNextStepsCardsProviding: AnyObject {
@MainActor
func dismiss(_ card: NewTabPageNextStepsCardsClient.CardID)

@MainActor
func willDisplayCards(_ cards: [NewTabPageNextStepsCardsClient.CardID])
}

0 comments on commit 1d00999

Please sign in to comment.