Skip to content

Commit

Permalink
[MBL-1761] Add pledge redemption deep links (#2166)
Browse files Browse the repository at this point in the history
* Add pledge redemption deeplinks to survey route

* Delete survey webview title

---------

Co-authored-by: Steve Streza <s.streza@kickstarter.com>
  • Loading branch information
ifosli and stevestreza-ksr authored Oct 7, 2024
1 parent a0ce7c9 commit 34ec6a0
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Kickstarter-iOS/AppDelegateViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ public final class AppDelegateViewModel: AppDelegateViewModelType, AppDelegateVi

let surveyUrlFromProjectLink = deepLink
.map { link -> String? in
if case let .project(_, .survey(surveyUrl), _) = link {
if case let .project(_, .surveyWebview(surveyUrl), _) = link {
return surveyUrl
}
return nil
Expand Down Expand Up @@ -1068,7 +1068,7 @@ private func navigation(fromPushEnvelope envelope: PushEnvelope) -> Navigation?
if let survey = envelope.survey {
let path = survey.urls.web.survey
let url = AppEnvironment.current.apiService.serverConfig.webBaseUrl.absoluteString + path
return .project(.id(survey.projectId), .survey(url), refInfo: RefInfo(.push))
return .project(.id(survey.projectId), .surveyWebview(url), refInfo: RefInfo(.push))
}

if let update = envelope.update {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ internal final class SurveyResponseViewController: WebViewController {
self?.goToPledge(param: param)
}

self.navigationItem.rac.title = self.viewModel.outputs.title

self.viewModel.outputs.webViewLoadRequest
.observeForControllerAction()
.observeValues { [weak self] request in
Expand Down
8 changes: 6 additions & 2 deletions Library/Navigation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public enum Navigation: Equatable {
case pledge(Navigation.Project.Pledge)
case updates
case update(Int, Navigation.Project.Update)
case survey(String)
case surveyWebview(String)

public enum Checkout: Equatable {
case thanks(racing: Bool?)
Expand Down Expand Up @@ -131,6 +131,8 @@ private let allRoutes: [String: (RouteParamsDecoded) -> Navigation?] = [
"/search": search,
"/signup": signup,
"/projects/:creator_param/:project_param": project,
"/projects/:creator_param/:project_param/backing/pledge_redemption": projectSurvey,
"/projects/:creator_param/:project_param/backing/redeem": projectSurvey,
"/projects/:creator_param/:project_param/checkouts/:checkout_param/thanks": thanks,
"/projects/:creator_param/:project_param/comments": projectComments,
"/projects/:creator_param/:project_param/creator_bio": creatorBio,
Expand Down Expand Up @@ -166,6 +168,8 @@ private let deepLinkRoutes: [String: (RouteParamsDecoded) -> Navigation?] = allR
"/messages/:message_thread_id",
"/profile/verify_email",
"/projects/:creator_param/:project_param",
"/projects/:creator_param/:project_param/backing/pledge_redemption",
"/projects/:creator_param/:project_param/backing/redeem",
"/projects/:creator_param/:project_param/comments",
"/projects/:creator_param/:project_param/description",
"/projects/:creator_param/:project_param/faqs",
Expand Down Expand Up @@ -425,7 +429,7 @@ private func projectSurvey(_ params: RouteParamsDecoded) -> Navigation? {
let path = params.path() {
let url = AppEnvironment.current.apiService.serverConfig.webBaseUrl.absoluteString + path
let refInfo = refInfoFromParams(params)
let survey = Navigation.Project.survey(url)
let survey = Navigation.Project.surveyWebview(url)
return Navigation.project(projectParam, survey, refInfo: refInfo)
}

Expand Down
2 changes: 1 addition & 1 deletion Library/NavigationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public final class NavigationTests: XCTestCase {
withEnvironment(apiService: MockService(serverConfig: ServerConfig.production)) {
self.assertProjectMatch(
path: "/projects/creator/project/surveys/3",
navigation: .survey("https://www.kickstarter.com/projects/creator/project/surveys/3")
navigation: .surveyWebview("https://www.kickstarter.com/projects/creator/project/surveys/3")
)
}

Expand Down
9 changes: 1 addition & 8 deletions Library/ViewModels/SurveyResponseViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ public protocol SurveyResponseViewModelOutputs {
/// Emits a project param that should be used to present the manage pledge view controller
var goToPledge: Signal<Param, Never> { get }

/// Set the navigation item's title.
var title: Signal<String, Never> { get }

/// Emits a request that should be loaded by the webview.
var webViewLoadRequest: Signal<URLRequest, Never> { get }
}
Expand Down Expand Up @@ -122,9 +119,6 @@ public final class SurveyResponseViewModel: SurveyResponseViewModelType {
}
.map { $0 ? .allow : .cancel }

self.title = self.viewDidLoadProperty.signal
.mapConst(Strings.Survey())

self.webViewLoadRequest = Signal.merge(
initialRequest,
newSurveyRequest
Expand Down Expand Up @@ -154,7 +148,6 @@ public final class SurveyResponseViewModel: SurveyResponseViewModelType {
public let goToProject: Signal<(Param, RefTag?), Never>
public let goToUpdate: Signal<(Project, Update), Never>
public let goToPledge: Signal<Param, Never>
public let title: Signal<String, Never>
public let webViewLoadRequest: Signal<URLRequest, Never>

public var inputs: SurveyResponseViewModelInputs { return self }
Expand All @@ -167,7 +160,7 @@ private func isUnpreparedSurvey(request: URLRequest) -> Bool {
}

private func isSurvey(request: URLRequest) -> Bool {
guard case (.project(_, .survey, _))? = Navigation.match(request) else { return false }
guard case (.project(_, .surveyWebview, _))? = Navigation.match(request) else { return false }
return true
}

Expand Down
10 changes: 0 additions & 10 deletions Library/ViewModels/SurveyResponseViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ final class SurveyResponseViewModelTests: TestCase {
fileprivate let goToPledge = TestObserver<Param, Never>()
fileprivate let goToProjectParam = TestObserver<Param, Never>()
fileprivate let goToUpdate = TestObserver<(Project, Update), Never>()
fileprivate let title = TestObserver<String, Never>()
fileprivate let webViewLoadRequestIsPrepared = TestObserver<Bool, Never>()
fileprivate let webViewLoadRequest = TestObserver<URLRequest, Never>()

Expand All @@ -23,7 +22,6 @@ final class SurveyResponseViewModelTests: TestCase {
self.vm.outputs.goToPledge.observe(self.goToPledge.observer)
self.vm.outputs.goToProject.map { $0.0 }.observe(self.goToProjectParam.observer)
self.vm.outputs.goToUpdate.observe(self.goToUpdate.observer)
self.vm.outputs.title.observe(self.title.observer)
self.vm.outputs.webViewLoadRequest
.map { AppEnvironment.current.apiService.isPrepared(request: $0) }
.observe(self.webViewLoadRequestIsPrepared.observer)
Expand Down Expand Up @@ -120,14 +118,6 @@ final class SurveyResponseViewModelTests: TestCase {
self.dismissViewController.assertValueCount(1)
}

func testTitle() {
self.vm.inputs.configureWith(surveyUrl: SurveyResponse.template.urls.web.survey)
self.title.assertValueCount(0)

self.vm.inputs.viewDidLoad()
self.title.assertValues([Strings.Survey()])
}

// MARK: - Test links

func testGoToPledge() {
Expand Down

0 comments on commit 34ec6a0

Please sign in to comment.