Skip to content

Commit

Permalink
[MBL-1218] Create RefInfo struct and use it where needed (#1953)
Browse files Browse the repository at this point in the history
* Create RefInfo struct

* Rename refTag files

* Update projectPageViewModel to take refInfo struct

* Update ProjectPageViewController to take in a RefInfo object

* Use refInfo in navigation
  • Loading branch information
ifosli committed Feb 23, 2024
1 parent c45a57e commit bb8fc44
Show file tree
Hide file tree
Showing 21 changed files with 225 additions and 198 deletions.
34 changes: 17 additions & 17 deletions Kickstarter-iOS/AppDelegateViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -446,26 +446,26 @@ public final class AppDelegateViewModel: AppDelegateViewModelType, AppDelegateVi
}

let projectLinkValues = deepLink
.map { link -> (Param, Navigation.Project, RefTag?)? in
guard case let .project(param, subpage, refTag) = link else { return nil }
return (param, subpage, refTag)
.map { link -> (Param, Navigation.Project, RefInfo?)? in
guard case let .project(param, subpage, refInfo) = link else { return nil }
return (param, subpage, refInfo)
}
.skipNil()
.switchMap { param, subpage, refTag in
.switchMap { param, subpage, refInfo in
AppEnvironment.current.apiService.fetchProject(param: param)
.demoteErrors()
.observeForUI()
.map { project -> (Project, Navigation.Project, [UIViewController], RefTag?) in
.map { project -> (Project, Navigation.Project, [UIViewController], RefInfo?) in
let projectParam = Either<Project, Param>(left: project)
let vc = ProjectPageViewController.configuredWith(
projectOrParam: projectParam,
refTag: refTag
refInfo: refInfo
)

return (
project, subpage,
[vc],
refTag
refInfo
)
}
}
Expand Down Expand Up @@ -1009,14 +1009,14 @@ private func navigation(fromPushEnvelope envelope: PushEnvelope) -> Navigation?
switch activity.category {
case .backing:
guard let projectId = activity.projectId else { return nil }
return .project(.id(projectId), .root, refTag: .push)
return .project(.id(projectId), .root, refInfo: RefInfo(.push))
case .failure, .launch, .success, .cancellation, .suspension:
guard let projectId = activity.projectId else { return nil }
return .project(.id(projectId), .root, refTag: .push)
return .project(.id(projectId), .root, refInfo: RefInfo(.push))

case .update:
guard let projectId = activity.projectId, let updateId = activity.updateId else { return nil }
return .project(.id(projectId), .update(updateId, .root), refTag: .push)
return .project(.id(projectId), .update(updateId, .root), refInfo: RefInfo(.push))

case .commentPost:
guard let projectId = activity.projectId, let updateId = activity.updateId else { return nil }
Expand All @@ -1025,18 +1025,18 @@ private func navigation(fromPushEnvelope envelope: PushEnvelope) -> Navigation?
return .project(
.id(projectId),
.update(updateId, .commentThread(commentId, activity.replyId)),
refTag: .push
refInfo: RefInfo(.push)
)
}
return .project(.id(projectId), .update(updateId, .comments), refTag: .push)
return .project(.id(projectId), .update(updateId, .comments), refInfo: RefInfo(.push))

case .commentProject:
guard let projectId = activity.projectId else { return nil }

if let commentId = activity.commentId {
return .project(.id(projectId), .commentThread(commentId, activity.replyId), refTag: .push)
return .project(.id(projectId), .commentThread(commentId, activity.replyId), refInfo: RefInfo(.push))
}
return .project(.id(projectId), .comments, refTag: .push)
return .project(.id(projectId), .comments, refInfo: RefInfo(.push))

case .follow:
return .tab(.activity)
Expand All @@ -1047,7 +1047,7 @@ private func navigation(fromPushEnvelope envelope: PushEnvelope) -> Navigation?
}

if let project = envelope.project {
return .project(.id(project.id), .root, refTag: .push)
return .project(.id(project.id), .root, refInfo: RefInfo(.push))
}

if let message = envelope.message {
Expand All @@ -1059,11 +1059,11 @@ private func navigation(fromPushEnvelope envelope: PushEnvelope) -> Navigation?
}

if let update = envelope.update {
return .project(.id(update.projectId), .update(update.id, .root), refTag: .push)
return .project(.id(update.projectId), .update(update.id, .root), refInfo: RefInfo(.push))
}

if let erroredPledge = envelope.erroredPledge {
return .project(.id(erroredPledge.projectId), .pledge(.manage), refTag: .push)
return .project(.id(erroredPledge.projectId), .pledge(.manage), refInfo: RefInfo(.push))
}

return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ internal final class ActivitiesViewController: UITableViewController {
let projectParam = Either<Project, Param>(left: project)
let vc = ProjectPageViewController.configuredWith(
projectOrParam: projectParam,
refTag: refTag
refInfo: RefInfo(refTag)
)

let nav = NavigationController(rootViewController: vc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ internal final class BackerDashboardProjectsViewController: UITableViewControlle
let projectParam = Either<Project, Param>(left: project)
let vc = ProjectPageViewController.configuredWith(
projectOrParam: projectParam,
refTag: refTag
refInfo: RefInfo(refTag)
)

let nav = NavigationController(rootViewController: vc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ final class CuratedProjectsViewController: UIViewController {
let projectParam = Either<Project, Param>(left: project)
let vc = ProjectPageViewController.configuredWith(
projectOrParam: projectParam,
refTag: refTag
refInfo: RefInfo(refTag)
)

let nav = NavigationController(rootViewController: vc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ internal final class DiscoveryPageViewController: UITableViewController {
let projectParam = Either<Project, Param>(left: project)
let vc = ProjectPageViewController.configuredWith(
projectOrParam: projectParam,
refTag: refTag
refInfo: RefInfo(refTag)
)

let nav = NavigationController(rootViewController: vc)
Expand All @@ -365,7 +365,7 @@ internal final class DiscoveryPageViewController: UITableViewController {
let projectParam = Either<Project, Param>(left: project)
let vc = ProjectPageViewController.configuredWith(
projectOrParam: projectParam,
refTag: refTag
refInfo: RefInfo(refTag)
)

let nav = NavigationController(rootViewController: vc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ internal final class MessagesViewController: UITableViewController, MessageBanne
let projectParam = Either<Project, Param>(left: project)
let vc = ProjectPageViewController.configuredWith(
projectOrParam: projectParam,
refTag: refTag
refInfo: RefInfo(refTag)
)

let nav = NavigationController(rootViewController: vc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ public final class ProjectPageViewController: UIViewController, MessageBannerVie

public static func configuredWith(
projectOrParam: Either<Project, Param>,
refTag: RefTag?
refInfo: RefInfo?
) -> ProjectPageViewController {
let vc = ProjectPageViewController.instantiate()

vc.viewModel.inputs.configureWith(projectOrParam: projectOrParam, refTag: refTag)
vc.viewModel.inputs.configureWith(projectOrParam: projectOrParam, refInfo: refInfo)

return vc
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ internal final class ProjectPageViewControllerConversionTests: TestCase {
)

withEnvironment(apiService: mockService, countryCode: "US") {
let vc = ProjectPageViewController.configuredWith(projectOrParam: .left(cosmicSurgery), refTag: nil)
let vc = ProjectPageViewController.configuredWith(projectOrParam: .left(cosmicSurgery), refInfo: nil)

let (parent, _) = traitControllers(device: Device.phone4_7inch, orientation: .portrait, child: vc)
parent.view.frame.size.height = 900
Expand All @@ -61,7 +61,7 @@ internal final class ProjectPageViewControllerConversionTests: TestCase {
)

withEnvironment(apiService: mockService, countryCode: "AU") {
let vc = ProjectPageViewController.configuredWith(projectOrParam: .left(cosmicSurgery), refTag: nil)
let vc = ProjectPageViewController.configuredWith(projectOrParam: .left(cosmicSurgery), refInfo: nil)
let (parent, _) = traitControllers(device: Device.phone4_7inch, orientation: .portrait, child: vc)
parent.view.frame.size.height = 900

Expand All @@ -86,7 +86,7 @@ internal final class ProjectPageViewControllerConversionTests: TestCase {
)

withEnvironment(apiService: mockService, countryCode: "US") {
let vc = ProjectPageViewController.configuredWith(projectOrParam: .left(cosmicSurgery), refTag: nil)
let vc = ProjectPageViewController.configuredWith(projectOrParam: .left(cosmicSurgery), refInfo: nil)
let (parent, _) = traitControllers(device: Device.phone4_7inch, orientation: .portrait, child: vc)
parent.view.frame.size.height = 900

Expand All @@ -111,7 +111,7 @@ internal final class ProjectPageViewControllerConversionTests: TestCase {
)

withEnvironment(apiService: mockService, countryCode: "CA") {
let vc = ProjectPageViewController.configuredWith(projectOrParam: .left(cosmicSurgery), refTag: nil)
let vc = ProjectPageViewController.configuredWith(projectOrParam: .left(cosmicSurgery), refInfo: nil)
let (parent, _) = traitControllers(device: Device.phone4_7inch, orientation: .portrait, child: vc)
parent.view.frame.size.height = 900

Expand Down Expand Up @@ -147,7 +147,7 @@ internal final class ProjectPageViewControllerConversionTests: TestCase {
)

withEnvironment(apiService: mockService, countryCode: "CA") {
let vc = ProjectPageViewController.configuredWith(projectOrParam: .left(cosmicSurgery), refTag: nil)
let vc = ProjectPageViewController.configuredWith(projectOrParam: .left(cosmicSurgery), refInfo: nil)
let (parent, _) = traitControllers(device: Device.phone4_7inch, orientation: .portrait, child: vc)
parent.view.frame.size.height = 900

Expand Down Expand Up @@ -178,7 +178,7 @@ internal final class ProjectPageViewControllerConversionTests: TestCase {
)

withEnvironment(apiService: mockService, countryCode: "SE") {
let vc = ProjectPageViewController.configuredWith(projectOrParam: .left(cosmicSurgery), refTag: nil)
let vc = ProjectPageViewController.configuredWith(projectOrParam: .left(cosmicSurgery), refInfo: nil)
let (parent, _) = traitControllers(device: Device.phone4_7inch, orientation: .portrait, child: vc)
parent.view.frame.size.height = 900

Expand All @@ -204,7 +204,7 @@ internal final class ProjectPageViewControllerConversionTests: TestCase {
)

withEnvironment(apiService: mockService, countryCode: "US") {
let vc = ProjectPageViewController.configuredWith(projectOrParam: .left(cosmicSurgery), refTag: nil)
let vc = ProjectPageViewController.configuredWith(projectOrParam: .left(cosmicSurgery), refInfo: nil)
let (parent, _) = traitControllers(device: Device.phone4_7inch, orientation: .portrait, child: vc)
parent.view.frame.size.height = 900

Expand All @@ -230,7 +230,7 @@ internal final class ProjectPageViewControllerConversionTests: TestCase {
)

withEnvironment(apiService: mockService, countryCode: "CA") {
let vc = ProjectPageViewController.configuredWith(projectOrParam: .left(cosmicSurgery), refTag: nil)
let vc = ProjectPageViewController.configuredWith(projectOrParam: .left(cosmicSurgery), refInfo: nil)
let (parent, _) = traitControllers(device: Device.phone4_7inch, orientation: .portrait, child: vc)
parent.view.frame.size.height = 900

Expand All @@ -256,7 +256,7 @@ internal final class ProjectPageViewControllerConversionTests: TestCase {
)

withEnvironment(apiService: mockService, countryCode: "XX") {
let vc = ProjectPageViewController.configuredWith(projectOrParam: .left(cosmicSurgery), refTag: nil)
let vc = ProjectPageViewController.configuredWith(projectOrParam: .left(cosmicSurgery), refInfo: nil)
let (parent, _) = traitControllers(device: Device.phone4_7inch, orientation: .portrait, child: vc)
parent.view.frame.size.height = 900

Expand Down

0 comments on commit bb8fc44

Please sign in to comment.