Skip to content

Commit

Permalink
Merge branch 'main' into dateFormatCrash
Browse files Browse the repository at this point in the history
  • Loading branch information
ifosli committed Sep 6, 2023
2 parents 924181b + 16567fe commit 9c50513
Show file tree
Hide file tree
Showing 20 changed files with 209 additions and 413 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ public final class ProjectPageViewController: UIViewController, MessageBannerVie
self.tableView.registerCellClass(ProjectFAQsAskAQuestionCell.self)
self.tableView.registerCellClass(ProjectFAQsCell.self)
self.tableView.registerCellClass(ProjectFAQsEmptyStateCell.self)
self.tableView.registerCellClass(ProjectTabQuestionAnswerCell.self)
self.tableView.registerCellClass(ProjectTabTitleCell.self)
self.tableView.registerCellClass(ProjectTabAIGenerationCell.self)
self.tableView.registerCellClass(ProjectTabCategoryDescriptionCell.self)
self.tableView.registerCellClass(ProjectTabDisclaimerCell.self)
self.tableView.registerCellClass(ProjectTabCheckmarkListCell.self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1040,17 +1040,7 @@ internal final class ProjectPageViewControllerTests: TestCase {
fundingForAiOption: true
)

let generatedByAIConsent = ProjectTabCategoryDescription(
description: "consent",
category: .aiDisclosureConsent,
id: 2
)

let generatedByAIDetails = ProjectTabCategoryDescription(
description: "details",
category: .aiDisclosureDetails,
id: 3
)
let generationDisclosure = ProjectTabGenerationDisclosure(consent: "consent", details: "details")

let generatedByAIOtherDetails = ProjectTabCategoryDescription(
description: "other",
Expand All @@ -1062,8 +1052,7 @@ internal final class ProjectPageViewControllerTests: TestCase {
ProjectAIDisclosure(
id: 1,
funding: projectTabFundingOptions,
generatedByAiConsent: generatedByAIConsent,
generatedByAiDetails: generatedByAIDetails,
generationDisclosure: generationDisclosure,
involvesAi: true,
involvesFunding: true,
involvesGeneration: true,
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -258,38 +258,12 @@ internal final class ProjectPageViewControllerDataSource: ValueCellDataSource {
)
}

if aiDisclosure.involvesGeneration {
self.appendRow(
value: Strings.I_plan_to_use_AI_generated_content(),
cellClass: ProjectTabTitleCell.self,
toSection: Section.aiDisclosureGenerated.rawValue
if aiDisclosure.involvesGeneration, let generationDisclosure = aiDisclosure.generationDisclosure {
self.set(
values: [generationDisclosure],
cellClass: ProjectTabAIGenerationCell.self,
inSection: Section.aiDisclosureGenerated.rawValue
)

if let detailsValues = aiDisclosure.generatedByAiDetails {
let value = (
GeneratedAIQuestionHeaderValue.partsOfProjectAIGenerated.description,
detailsValues.description
)
self
.appendRow(
value: value,
cellClass: ProjectTabQuestionAnswerCell.self,
toSection: Section.aiDisclosureGenerated.rawValue
)
}

if let consentValues = aiDisclosure.generatedByAiConsent {
let value = (
GeneratedAIQuestionHeaderValue.doYouHaveConsentOfOwners.description,
consentValues.description
)
self
.appendRow(
value: value,
cellClass: ProjectTabQuestionAnswerCell.self,
toSection: Section.aiDisclosureGenerated.rawValue
)
}
}

if let otherAIDetailValues = aiDisclosure.otherAiDetails, aiDisclosure.involvesOther {
Expand Down Expand Up @@ -330,9 +304,7 @@ internal final class ProjectPageViewControllerDataSource: ValueCellDataSource {

override func configureCell(tableCell cell: UITableViewCell, withValue value: Any) {
switch (cell, value) {
case let (cell as ProjectTabTitleCell, value as String):
cell.configureWith(value: value)
case let (cell as ProjectTabQuestionAnswerCell, value as (String, String)):
case let (cell as ProjectTabAIGenerationCell, value as ProjectTabGenerationDisclosure):
cell.configureWith(value: value)
case let (cell as ProjectTabCategoryDescriptionCell, value as ProjectTabCategoryDescription):
cell.configureWith(value: value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,8 @@ final class ProjectPageViewControllerDataSourceTests: XCTestCase {
fundingForAiOption: true
)

private let generatedByAIConsent = ProjectTabCategoryDescription(
description: "consent",
category: .aiDisclosureConsent,
id: 2
)

private let generatedByAIDetails = ProjectTabCategoryDescription(
description: "details",
category: .aiDisclosureDetails,
id: 3
private let generationDisclosure = ProjectTabGenerationDisclosure(
consent: "consent", details: "details"
)

private let generatedByAIOtherDetails = ProjectTabCategoryDescription(
Expand All @@ -38,8 +30,7 @@ final class ProjectPageViewControllerDataSourceTests: XCTestCase {
ProjectAIDisclosure(
id: 1,
funding: self.projectTabFundingOptions,
generatedByAiConsent: self.generatedByAIConsent,
generatedByAiDetails: self.generatedByAIDetails,
generationDisclosure: self.generationDisclosure,
involvesAi: true,
involvesFunding: true,
involvesGeneration: true,
Expand Down Expand Up @@ -420,7 +411,7 @@ final class ProjectPageViewControllerDataSourceTests: XCTestCase {
)

XCTAssertEqual(
3,
1,
self.dataSource
.tableView(self.tableView, numberOfRowsInSection: self.useOfAIDisclosureGeneratedSection)
)
Expand Down Expand Up @@ -451,15 +442,10 @@ final class ProjectPageViewControllerDataSourceTests: XCTestCase {
)

XCTAssertEqual(
"ProjectTabTitleCell",
"ProjectTabAIGenerationCell",
self.dataSource.reusableId(item: 0, section: self.useOfAIDisclosureGeneratedSection)
)

XCTAssertEqual(
"ProjectTabQuestionAnswerCell",
self.dataSource.reusableId(item: 1, section: self.useOfAIDisclosureGeneratedSection)
)

XCTAssertEqual(
"ProjectTabCategoryDescriptionCell",
self.dataSource.reusableId(item: 0, section: self.useOfAIDisclosureOtherDetailsSection)
Expand All @@ -471,7 +457,8 @@ final class ProjectPageViewControllerDataSourceTests: XCTestCase {
var updatedUseOfAIDisclosure = self.useOfAIDisclosure

updatedUseOfAIDisclosure.involvesFunding = false
updatedUseOfAIDisclosure.generatedByAiDetails = nil
updatedUseOfAIDisclosure.generationDisclosure =
ProjectTabGenerationDisclosure(consent: "consent", details: nil)

let project = Project.template
|> \.extendedProjectProperties .~ ExtendedProjectProperties(
Expand Down Expand Up @@ -505,7 +492,7 @@ final class ProjectPageViewControllerDataSourceTests: XCTestCase {
)

XCTAssertEqual(
2,
1,
self.dataSource
.tableView(self.tableView, numberOfRowsInSection: self.useOfAIDisclosureGeneratedSection)
)
Expand Down Expand Up @@ -535,15 +522,10 @@ final class ProjectPageViewControllerDataSourceTests: XCTestCase {
)

XCTAssertEqual(
"ProjectTabTitleCell",
"ProjectTabAIGenerationCell",
self.dataSource.reusableId(item: 0, section: self.useOfAIDisclosureGeneratedSection)
)

XCTAssertEqual(
"ProjectTabQuestionAnswerCell",
self.dataSource.reusableId(item: 1, section: self.useOfAIDisclosureGeneratedSection)
)

XCTAssertEqual(
"ProjectTabCategoryDescriptionCell",
self.dataSource.reusableId(item: 0, section: self.useOfAIDisclosureOtherDetailsSection)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
import KsApi
import Library
import Prelude
import UIKit

final class ProjectTabAIGenerationCell: UITableViewCell, ValueCell {
// MARK: - Properties

private var consentText: String?
private var detailsText: String?

private lazy var categoryLabel: UILabel = {
UILabel(frame: .zero)
|> \.translatesAutoresizingMaskIntoConstraints .~ false
|> \.text .~ Strings.I_plan_to_use_AI_generated_content()
}()

private lazy var rootStackView = {
UIStackView(frame: .zero)
|> \.translatesAutoresizingMaskIntoConstraints .~ false
}()

// MARK: - Lifecycle

override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)

self.bindStyles()
self.configureViews()
self.bindViewModel()
}

required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

// MARK: - Bindings

override func bindStyles() {
super.bindStyles()

_ = self
|> baseTableViewCellStyle()
|> \.separatorInset .~ .init(leftRight: Styles.projectPageLeftRightInset)

_ = self.contentView
|> \.layoutMargins .~
.init(topBottom: Styles.grid(2), leftRight: Styles.projectPageLeftRightInset)

_ = self.rootStackView
|> rootStackViewStyle

_ = self.categoryLabel
|> categoryLabelStyle
}

// MARK: - Configuration

func configureWith(value: ProjectTabGenerationDisclosure) {
self.rootStackView.arrangedSubviews.forEach { $0.removeFromSuperview() }
self.rootStackView.addArrangedSubview(self.categoryLabel)

if let detailsText = value.details {
let detailsView = view(
question: Strings.What_parts_of_your_project_will_use_AI_generated_content(),
answer: detailsText
)
self.rootStackView.addArrangedSubview(detailsView)
}

if let consentText = value.consent {
let consentView = view(
question: Strings.Do_you_have_the_consent_of_the_owners_of_the_works_used_for_AI(),
answer: consentText
)
self.rootStackView.addArrangedSubview(consentView)
}
}

private func configureViews() {
_ = (self.rootStackView, self.contentView)
|> ksr_addSubviewToParent()
|> ksr_constrainViewToMarginsInParent()
}
}

// MARK: - Helpers

private func view(question: String, answer: String) -> UIView {
let container = {
UIView(frame: .zero)
|> \.translatesAutoresizingMaskIntoConstraints .~ false
}()

let questionLabel = UILabel(frame: .zero)
|> questionLabelStyle
|> \.text .~ question
container.addSubview(questionLabel)

let answerLabel = UILabel(frame: .zero)
|> answerLabelStyle
|> \.text .~ answer
container.addSubview(answerLabel)

let answerBar = UIView(frame: .zero)
|> answerBarStyle
container.addSubview(answerBar)

NSLayoutConstraint.activate([
questionLabel.leadingAnchor.constraint(equalTo: container.leadingAnchor),
questionLabel.trailingAnchor
.constraint(equalTo: container.trailingAnchor),
questionLabel.topAnchor.constraint(equalTo: container.topAnchor),

answerBar.leadingAnchor.constraint(equalTo: questionLabel.leadingAnchor),
answerBar.widthAnchor.constraint(equalToConstant: Styles.grid(1)),
answerBar.topAnchor.constraint(equalTo: answerLabel.topAnchor),
answerBar.bottomAnchor.constraint(equalTo: answerLabel.bottomAnchor),

answerLabel.leadingAnchor
.constraint(equalTo: answerBar.trailingAnchor, constant: Styles.grid(2)),
answerLabel.topAnchor
.constraint(equalTo: questionLabel.bottomAnchor, constant: Styles.grid(2)),
answerLabel.trailingAnchor.constraint(equalTo: questionLabel.trailingAnchor),
answerLabel.bottomAnchor.constraint(equalTo: container.bottomAnchor)
])

return container
}

// MARK: - Styles

private let categoryLabelStyle: LabelStyle = { label in
label
|> \.adjustsFontForContentSizeCategory .~ true
|> \.font .~ UIFont.ksr_title3().bolded
|> \.numberOfLines .~ 0
|> \.textColor .~ .ksr_support_700
}

private let answerLabelStyle: LabelStyle = { label in
label
|> \.adjustsFontForContentSizeCategory .~ true
|> \.font .~ UIFont.ksr_body()
|> \.numberOfLines .~ 0
|> \.textColor .~ .ksr_support_700
|> \.translatesAutoresizingMaskIntoConstraints .~ false
}

private let questionLabelStyle: LabelStyle = { label in
label
|> \.font .~ UIFont.ksr_body().bolded
|> \.numberOfLines .~ 0
|> \.textColor .~ .ksr_support_700
|> \.translatesAutoresizingMaskIntoConstraints .~ false
}

private let answerBarStyle: ViewStyle = { view in
view
|> \.backgroundColor .~ .ksr_create_700
|> \.translatesAutoresizingMaskIntoConstraints .~ false
}

private let rootStackViewStyle: StackViewStyle = { stackView in
stackView
|> \.axis .~ .vertical
|> \.insetsLayoutMarginsFromSafeArea .~ false
|> \.isLayoutMarginsRelativeArrangement .~ true
|> \.spacing .~ Styles.grid(3)
}

0 comments on commit 9c50513

Please sign in to comment.