Skip to content

Commit

Permalink
Domain: Refactor to use a common domain selection view (#22254)
Browse files Browse the repository at this point in the history
  • Loading branch information
staskus authored Dec 22, 2023
2 parents 2b6639d + 1b8ecaf commit 7720c9e
Show file tree
Hide file tree
Showing 31 changed files with 547 additions and 1,513 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public extension Color {
private static func colorWithModuleBundle(colorName: String) -> Color {
Color(colorName, bundle: .module)
}

public static func custom(_ colorName: String) -> Color {
return colorWithModuleBundle(colorName: colorName)
}
}
}

Expand Down
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
24.0
-----
* [**] [internal] A minor refactor in authentication flow, including but not limited to social sign-in and two factor authentication. [#22086]
* [**] [internal] Refactor domain selection flows to use the same domain selection UI. [22254]

23.9
-----
Expand Down
44 changes: 7 additions & 37 deletions WordPress/Classes/Services/SiteAddressService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,13 @@ struct SiteAddressServiceResult {
typealias SiteAddressServiceCompletion = (Result<SiteAddressServiceResult, Error>) -> Void

protocol SiteAddressService {
func addresses(for query: String, segmentID: Int64, completion: @escaping SiteAddressServiceCompletion)
func addresses(for query: String, completion: @escaping SiteAddressServiceCompletion)
func addresses(for query: String, type: DomainsServiceRemote.DomainSuggestionType, completion: @escaping SiteAddressServiceCompletion)
}

// MARK: - MockSiteAddressService

final class MockSiteAddressService: SiteAddressService {
func addresses(for query: String, segmentID: Int64, completion: @escaping SiteAddressServiceCompletion) {
completion(.success(SiteAddressServiceResult(hasExactMatch: true, domainSuggestions: mockAddresses)))
}

func addresses(for query: String, completion: @escaping SiteAddressServiceCompletion) {
func addresses(for query: String, type: DomainsServiceRemote.DomainSuggestionType, completion: @escaping SiteAddressServiceCompletion) {
completion(.success(SiteAddressServiceResult(hasExactMatch: true, domainSuggestions: mockAddresses)))
}

Expand All @@ -51,11 +46,6 @@ final class DomainsServiceAdapter: SiteAddressService {

// MARK: Properties

/// Checks if the Domain Purchasing Feature Flag and AB Experiment are enabled
private var domainPurchasingEnabled: Bool {
RemoteFeatureFlag.plansInSiteCreation.enabled()
}

/**
Corresponds to:
Expand Down Expand Up @@ -98,38 +88,18 @@ final class DomainsServiceAdapter: SiteAddressService {

// MARK: SiteAddressService

func addresses(for query: String, segmentID: Int64, completion: @escaping SiteAddressServiceCompletion) {

domainsService.getDomainSuggestions(query: query,
segmentID: segmentID,
quantity: domainRequestQuantity,
success: { domainSuggestions in
completion(Result.success(self.sortSuggestions(for: query, suggestions: domainSuggestions)))
},
failure: { error in
if (error as NSError).code == DomainsServiceAdapter.emptyResultsErrorCode {
completion(Result.success(SiteAddressServiceResult()))
return
}

completion(Result.failure(error))
})
}

func addresses(for query: String, completion: @escaping SiteAddressServiceCompletion) {
let domainSuggestionType: DomainsServiceRemote.DomainSuggestionType = domainPurchasingEnabled
? .freeAndPaid
: .wordPressDotComAndDotBlogSubdomains
func addresses(for query: String, type: DomainsServiceRemote.DomainSuggestionType, completion: @escaping SiteAddressServiceCompletion) {
domainsService.getDomainSuggestions(query: query,
quantity: domainRequestQuantity,
domainSuggestionType: domainSuggestionType,
domainSuggestionType: type,
success: { domainSuggestions in
if self.domainPurchasingEnabled {
switch type {
case .freeAndPaid:
let hasExactMatch = domainSuggestions.contains { domain -> Bool in
return domain.domainNameStrippingSubdomain.caseInsensitiveCompare(query) == .orderedSame
}
completion(Result.success(.init(hasExactMatch: hasExactMatch, domainSuggestions: domainSuggestions)))
} else {
default:
completion(Result.success(self.sortSuggestions(for: query, suggestions: domainSuggestions)))
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import SwiftUI
blog: Blog
) {
let coordinator = RegisterDomainCoordinator(site: blog)
let domainSuggestionsViewController = RegisterDomainSuggestionsViewController.instance(
coordinator: coordinator,
let domainSuggestionsViewController = DomainSelectionViewController(
service: DomainsServiceAdapter(coreDataStack: ContextManager.shared),
domainSelectionType: .purchaseWithPaidPlan,
includeSupportButton: false
includeSupportButton: false,
coordinator: coordinator
)

let purchaseCallback = { (checkoutViewController: UIViewController, domainName: String) in
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -1035,15 +1035,6 @@ - (void)configureTableViewData
[marr addNullableObject:[self jetpackCardSectionViewModel]];
}

// This code will be removed in a future PR.
// if ([DomainCreditEligibilityChecker canRedeemDomainCreditWithBlog:self.blog]) {
// if (!self.hasLoggedDomainCreditPromptShownEvent) {
// [WPAnalytics track:WPAnalyticsStatDomainCreditPromptShown];
// self.hasLoggedDomainCreditPromptShownEvent = YES;
// }
// [marr addNullableObject:[self domainCreditSectionViewModel]];
// }

if ([self shouldShowQuickStartChecklist]) {
[marr addNullableObject:[self quickStartSectionViewModel]];
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class RegisterDomainDetailsViewModel {

var registerDomainDetailsService: RegisterDomainDetailsServiceProxyProtocol = RegisterDomainDetailsServiceProxy()

let domain: FullyQuotedDomainSuggestion
let domain: DomainSuggestion
let siteID: Int
let domainPurchasedCallback: ((String) -> Void)

Expand All @@ -68,7 +68,7 @@ class RegisterDomainDetailsViewModel {
}
}

init(siteID: Int, domain: FullyQuotedDomainSuggestion, domainPurchasedCallback: @escaping ((String) -> Void)) {
init(siteID: Int, domain: DomainSuggestion, domainPurchasedCallback: @escaping ((String) -> Void)) {
self.siteID = siteID
self.domain = domain
self.domainPurchasedCallback = domainPurchasedCallback
Expand Down Expand Up @@ -193,7 +193,7 @@ class RegisterDomainDetailsViewModel {

registerDomainService.purchaseDomainUsingCredits(
siteID: siteID,
domainSuggestion: domainSuggestion.remoteSuggestion(),
domainSuggestion: domainSuggestion,
domainContactInformation: contactInformation,
privacyProtectionEnabled: privacyEnabled,
success: { domain in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import SwiftUI
import UIKit
import WordPressKit

/// Makes RegisterDomainSuggestionsViewController available to SwiftUI
/// Makes DomainSelectionViewController available to SwiftUI
struct DomainSuggestionViewControllerWrapper: UIViewControllerRepresentable {

private let blog: Blog
private let domainSelectionType: DomainSelectionType
private let onDismiss: () -> Void

private var domainSuggestionViewController: RegisterDomainSuggestionsViewController
private var domainSuggestionViewController: DomainSelectionViewController

init(blog: Blog, domainSelectionType: DomainSelectionType, onDismiss: @escaping () -> Void) {
self.blog = blog
Expand Down
Loading

0 comments on commit 7720c9e

Please sign in to comment.