Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MBL-978] Remove creator dashboard button #1864

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -841,8 +841,6 @@ extension ProjectPageViewController: UITableViewDelegate {
cell.delegate = self
} else if let cell = cell as? ProjectPamphletMainCell, playbackDelegate == nil {
playbackDelegate = cell
} else if let cell = cell as? ProjectPamphletCreatorHeaderCell {
cell.delegate = self
} else if let cell = cell as? ImageViewElementCell {
cell.pinchToZoomDelegate = self
}
Expand Down Expand Up @@ -974,17 +972,6 @@ extension ProjectPageViewController: ProjectPamphletMainCellDelegate {
}
}

// MARK: ProjectPamphletCreatorHeaderCellDelegate

extension ProjectPageViewController: ProjectPamphletCreatorHeaderCellDelegate {
func projectPamphletCreatorHeaderCellDidTapViewProgress(
_: ProjectPamphletCreatorHeaderCell,
with project: Project
) {
self.viewModel.inputs.tappedViewProgress(of: project)
}
}

// MARK: - Styles

private let tableViewStyle: TableViewStyle = { tableView in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,18 @@
import Prelude
import UIKit

private enum Layout {
enum Button {
static let height: CGFloat = 48
static let width: CGFloat = 152
}
}

protocol ProjectPamphletCreatorHeaderCellDelegate: AnyObject {
func projectPamphletCreatorHeaderCellDidTapViewProgress(
_ cell: ProjectPamphletCreatorHeaderCell,
with project: Project
)
}

final class ProjectPamphletCreatorHeaderCell: UITableViewCell, ValueCell {
// MARK: Properties

private let launchDateLabel: UILabel = { UILabel(frame: .zero) }()
private let rootStackView: UIStackView = { UIStackView(frame: .zero) }()
private let viewProgressButton: UIButton = { UIButton(frame: .zero) }()
private let viewModel: ProjectPamphletCreatorHeaderCellViewModelType =
ProjectPamphletCreatorHeaderCellViewModel()

internal weak var delegate: ProjectPamphletCreatorHeaderCellDelegate?

// MARK: Lifecycle

override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.configureViews()
self.setupConstraints()
self.bindViewModel()
}

Expand All @@ -48,39 +29,16 @@
}

private func configureViews() {
_ = ([self.launchDateLabel, self.viewProgressButton], self.rootStackView)
|> ksr_addArrangedSubviewsToStackView()

_ = (self.rootStackView, self.contentView)
_ = (self.launchDateLabel, self.contentView)

Check warning on line 32 in Kickstarter-iOS/Features/ProjectPage/Views/Cells/ProjectPamphletCreatorHeaderCell.swift

View check run for this annotation

Codecov / codecov/patch

Kickstarter-iOS/Features/ProjectPage/Views/Cells/ProjectPamphletCreatorHeaderCell.swift#L32

Added line #L32 was not covered by tests
|> ksr_addSubviewToParent()
|> ksr_constrainViewToMarginsInParent()

self.viewProgressButton.addTarget(
self, action: #selector(self.viewProgressButtonTapped), for: .touchUpInside
)
}

private func setupConstraints() {
NSLayoutConstraint.activate([
self.viewProgressButton.heightAnchor.constraint(equalToConstant: Layout.Button.height),
self.viewProgressButton.widthAnchor.constraint(equalToConstant: Layout.Button.width)
])
}

// MARK: - View model

override func bindViewModel() {
super.bindViewModel()
self.launchDateLabel.rac.attributedText = self.viewModel.outputs.launchDateLabelAttributedText
self.viewProgressButton.rac.title = self.viewModel.outputs.buttonTitle

self.viewModel.outputs.notifyDelegateViewProgressButtonTapped
.observeForUI()
.observeValues { [weak self] project in
guard let self = self else { return }

self.delegate?.projectPamphletCreatorHeaderCellDidTapViewProgress(self, with: project)
}
}

// MARK: - Styles
Expand All @@ -93,21 +51,6 @@

_ = self.launchDateLabel
|> projectCreationInfoLabelStyle

_ = self.rootStackView
|> adaptableStackViewStyle(
self.traitCollection.preferredContentSizeCategory.isAccessibilityCategory
)
|> rootStackViewStyle

_ = self.viewProgressButton
|> viewProgressButtonStyle
}

// MARK: - Actions

@objc private func viewProgressButtonTapped() {
self.viewModel.inputs.viewProgressButtonTapped()
}
}

Expand All @@ -128,13 +71,3 @@
|> \.adjustsFontForContentSizeCategory .~ true
|> \.numberOfLines .~ 0
}

private let rootStackViewStyle: StackViewStyle = { stackView in
stackView
|> \.spacing .~ Styles.grid(1)
}

private let viewProgressButtonStyle: ButtonStyle = { button in
button
|> greyButtonStyle
}
8 changes: 0 additions & 8 deletions Library/ViewModels/ProjectPageViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ public protocol ProjectPageViewModelInputs {
/// Call when didSelectRow is called on the report project cell.
func tappedReportProject()

/// Call when the creator header cell progress view is tapped.
func tappedViewProgress(of project: Project)

/// Call when the user session starts and we want to reload the data source.
func userSessionStarted()

Expand Down Expand Up @@ -590,11 +587,6 @@ public final class ProjectPageViewModel: ProjectPageViewModelType, ProjectPageVi
self.tappedReportProjectProperty.value = ()
}

fileprivate let tappedViewProgressProperty = MutableProperty<Project?>(nil)
public func tappedViewProgress(of project: Project) {
self.tappedViewProgressProperty.value = project
}

fileprivate let userSessionStartedProperty = MutableProperty(())
public func userSessionStarted() {
self.userSessionStartedProperty.value = ()
Expand Down
21 changes: 0 additions & 21 deletions Library/ViewModels/ProjectPamphletCreatorHeaderCellViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import UIKit

public protocol ProjectPamphletCreatorHeaderCellViewModelInputs {
func configure(with project: Project)
func viewProgressButtonTapped()
}

public protocol ProjectPamphletCreatorHeaderCellViewModelOutputs {
var buttonTitle: Signal<String, Never> { get }
var launchDateLabelAttributedText: Signal<NSAttributedString, Never> { get }
var notifyDelegateViewProgressButtonTapped: Signal<Project, Never> { get }
}

public protocol ProjectPamphletCreatorHeaderCellViewModelType {
Expand All @@ -22,40 +19,22 @@ public protocol ProjectPamphletCreatorHeaderCellViewModelType {
public final class ProjectPamphletCreatorHeaderCellViewModel: ProjectPamphletCreatorHeaderCellViewModelType,
ProjectPamphletCreatorHeaderCellViewModelInputs, ProjectPamphletCreatorHeaderCellViewModelOutputs {
public init() {
self.buttonTitle = self.projectSignal
.map(title(for:))

self.launchDateLabelAttributedText = self.projectSignal
.map(attributedLaunchDateString(with:))
.skipNil()

self.notifyDelegateViewProgressButtonTapped = self.projectSignal
.takeWhen(self.viewProgressButtonTappedSignal.ignoreValues())
}

private let (projectSignal, projectObserver) = Signal<Project, Never>.pipe()
public func configure(with project: Project) {
self.projectObserver.send(value: project)
}

private let (viewProgressButtonTappedSignal, viewProgressButtonTappedObserver) =
Signal<Void, Never>.pipe()
public func viewProgressButtonTapped() {
self.viewProgressButtonTappedObserver.send(value: ())
}

public let buttonTitle: Signal<String, Never>
public let launchDateLabelAttributedText: Signal<NSAttributedString, Never>
public let notifyDelegateViewProgressButtonTapped: Signal<Project, Never>

public var inputs: ProjectPamphletCreatorHeaderCellViewModelInputs { return self }
public var outputs: ProjectPamphletCreatorHeaderCellViewModelOutputs { return self }
}

private func title(for project: Project) -> String {
return project.state == .live ? Strings.View_progress() : Strings.View_dashboard()
}

private func attributedLaunchDateString(with project: Project) -> NSAttributedString? {
var launchDate = ""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,13 @@ import ReactiveExtensions_TestHelpers
final class ProjectPamphletCreatorHeaderCellViewModelTests: TestCase {
private let vm: ProjectPamphletCreatorHeaderCellViewModelType = ProjectPamphletCreatorHeaderCellViewModel()

private let buttonTitle = TestObserver<String, Never>()
private let launchDateLabelAttributedText = TestObserver<String, Never>()
private let notifyDelegateViewProgressButtonTapped = TestObserver<Project, Never>()

override func setUp() {
super.setUp()

self.vm.outputs.buttonTitle.observe(self.buttonTitle.observer)
self.vm.outputs.launchDateLabelAttributedText.map { $0.string }
.observe(self.launchDateLabelAttributedText.observer)
self.vm.outputs.notifyDelegateViewProgressButtonTapped.observe(
self.notifyDelegateViewProgressButtonTapped.observer
)
}

func testButtonTitle_LiveProject() {
let project = Project.template
|> \.state .~ .live

self.buttonTitle.assertDidNotEmitValue()

self.vm.inputs.configure(with: project)

self.buttonTitle.assertValue("View progress")
}

func testButtonTitle_NonLiveProject() {
let project = Project.template
|> \.state .~ .successful

self.buttonTitle.assertDidNotEmitValue()

self.vm.inputs.configure(with: project)

self.buttonTitle.assertValue("View dashboard")
}

func testLaunchDateLabelAttributedText() {
Expand All @@ -67,15 +39,4 @@ final class ProjectPamphletCreatorHeaderCellViewModelTests: TestCase {
self.launchDateLabelAttributedText.assertValue("You launched this project on November 7, 2019.")
}
}

func testNotifyDelegateViewProgressButtonTapped() {
let project = Project.template
self.vm.inputs.configure(with: project)

self.notifyDelegateViewProgressButtonTapped.assertDidNotEmitValue()

self.vm.inputs.viewProgressButtonTapped()

self.notifyDelegateViewProgressButtonTapped.assertValue(project)
}
}