Skip to content
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
23 changes: 16 additions & 7 deletions DE/DE/Sources/Core/CommonUI/Cells/ReviewCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import Then
import DesignSystem

public class ReviewCollectionViewCell: UICollectionViewCell {

public static let identifier = "ReviewCollectionViewCell"

var isExpanded = false
private var toggleBottomConstraint: Constraint?
private var reviewBottomConstraint: Constraint?
Expand All @@ -17,6 +17,7 @@ public class ReviewCollectionViewCell: UICollectionViewCell {
public lazy var nickname = UILabel().then {
$0.textColor = AppColor.gray100
$0.font = UIFont.pretendard(.medium, size: 16)
$0.setContentHuggingPriority(.required, for: .vertical)
}

public lazy var score = UILabel()
Expand Down Expand Up @@ -60,6 +61,7 @@ public class ReviewCollectionViewCell: UICollectionViewCell {

private func addComponents() {
contentView.addSubviews(nickname, score, review, date, toggleButton)

}

private func constraints() {
Expand All @@ -85,7 +87,7 @@ public class ReviewCollectionViewCell: UICollectionViewCell {
}

toggleButton.snp.makeConstraints {
$0.top.equalTo(review.snp.bottom).offset(2)
$0.top.greaterThanOrEqualTo(review.snp.bottom).offset(2)
$0.leading.equalTo(review.snp.leading)
$0.bottom.equalToSuperview().offset(-10)
self.toggleBottomConstraint = $0.bottom.equalToSuperview().offset(-12).constraint
Expand All @@ -96,6 +98,8 @@ public class ReviewCollectionViewCell: UICollectionViewCell {
AppTextStyle.KR.body1.apply(to: nickname, text: model.name, color: AppColor.gray100)
AppTextStyle.KR.body2
.apply(to: score, text: "★ \(String(model.rating))", color: AppColor.purple100)


AppTextStyle.KR.body3.apply(to: review, text: model.contents, color: AppColor.gray90)

if let data = model.createdAt.toFlexibleDotFormattedDate() {
Expand All @@ -106,25 +110,30 @@ public class ReviewCollectionViewCell: UICollectionViewCell {
review.numberOfLines = isExpanded ? 0 : 2
toggleButton.setTitle(isExpanded ? "접기" : "더보기", for: .normal)
let shouldShowToggle = isReviewTextTruncated()
toggleButton.isHidden = !shouldShowToggle
toggleButton.isHidden = !(shouldShowToggle > 2)

// 리뷰내 2줄 초과인지 아닌지에 따른 제약 활성화/비활성화
if shouldShowToggle {
if shouldShowToggle > 2 {
toggleBottomConstraint?.activate()
reviewBottomConstraint?.deactivate()
} else {
toggleBottomConstraint?.deactivate()
reviewBottomConstraint?.activate()
}

if shouldShowToggle == 1 {
let reviewString = "\(model.contents)\n"
AppTextStyle.KR.body3.apply(to: review, text: reviewString, color: AppColor.gray90)
}
}

private func isReviewTextTruncated() -> Bool {
guard let text = review.text else { return false }
private func isReviewTextTruncated() -> Int {
guard let text = review.text else { return 0 }

let labelWidth = contentView.frame.width - 30
let labelFont = review.font ?? UIFont.systemFont(ofSize: 16)
let lineSpacing = review.font.pointSize * 0.3
let numberOfLines = text.numberOfLines(width: labelWidth, font: labelFont, lineSpacing: lineSpacing)
return numberOfLines > 2
return numberOfLines
}
}
6 changes: 6 additions & 0 deletions DE/DE/Sources/Core/CommonUI/View/ReviewView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,13 @@ public class ReviewView: UIView {
noReviewLabel.sizeToFit()
}

@MainActor
public func configure(_ model: WineAverageReviewModel) {
score = model.avgMemberRating
}

@MainActor
public func configureButton(_ isHidden: Bool) {
moreBtn.isHidden = isHidden
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ class EntireReviewViewController: UIViewController, FirebaseTrackable {
view.addSubview(indicator)
view.showColorBlockingView()
setupDropdownAction()
}

public override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
logScreenView(fileName: #file)

Task {
do {
try await callEntireReviewAPI(wineId: self.wineId, sortType: "최신순", page: 0)
try await callEntireReviewAPI(
wineId: self.wineId,
sortType: "최신순",
page: 0,
vintage: vintage
)
self.view.hideBlockingView()
} catch {
self.view.hideBlockingView()
Expand All @@ -58,6 +58,11 @@ class EntireReviewViewController: UIViewController, FirebaseTrackable {
}
}

public override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
logScreenView(fileName: #file)
}

private func setupNavigationBar() {
navigationBarManager.addBackButton(
to: navigationItem,
Expand Down Expand Up @@ -105,8 +110,10 @@ class EntireReviewViewController: UIViewController, FirebaseTrackable {

private func setupDropdownAction() {
logButtonClick(screenName: screenName, buttonName: Tracking.ButtonEvent.dropdownBtnTapped, fileName: #file)

entireReviewView.dropdownView.onOptionSelected = { [weak self] selectedOption in
guard let self = self else { return }

if selectedOption == "최신 순" {
currentType = "최신순"
} else if selectedOption == "오래된 순" {
Expand All @@ -117,9 +124,16 @@ class EntireReviewViewController: UIViewController, FirebaseTrackable {
currentType = "별점 낮은 순"
}
self.view.showBlockingView()

Task {
do {
try await self.callEntireReviewAPI(wineId: self.wineId, sortType: self.currentType, page: 0)
try await self.callEntireReviewAPI(
wineId: self.wineId,
sortType: self.currentType,
page: 0,
vintage: self.vintage
)

DispatchQueue.main.async {
// 강제로 맨위로 올리기
self.entireReviewView.reviewCollectionView.setContentOffset(.zero, animated: true)
Expand All @@ -134,7 +148,12 @@ class EntireReviewViewController: UIViewController, FirebaseTrackable {
}

func callEntireReviewAPI(wineId: Int, sortType: String, page: Int, vintage: Int? = nil) async throws {
guard let response = try await networkService.fetchWineReviews(wineId: wineId, vintageYear: vintage, sortType: sortType, page: page) else {
guard let response = try await networkService.fetchWineReviews(
wineId: wineId,
vintageYear: vintage,
sortType: sortType,
page: page
) else {
return
}

Expand Down Expand Up @@ -242,7 +261,12 @@ extension EntireReviewViewController: UICollectionViewDataSource, UICollectionVi
self.view.showBlockingView()
Task {
do {
try await callEntireReviewAPI(wineId: self.wineId, sortType: currentType, page: currentPage + 1)
try await callEntireReviewAPI(
wineId: self.wineId,
sortType: currentType,
page: currentPage + 1,
vintage: vintage
)
self.view.hideBlockingView()
} catch {
self.view.hideBlockingView()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,9 @@ class WineDetailViewController: UIViewController, UIScrollViewDelegate, Firebase
}

private func updateReviewView() {
reviewView.configureButton(reviewData.count != 3)

if reviewData.isEmpty {
// 리뷰가 없을 때
reviewView.moreBtn.isHidden = true
reviewView.reviewCollectionView.isHidden = true
reviewView.reviewCollectionView.snp.updateConstraints {
$0.height.equalTo(0)
Expand All @@ -318,7 +318,6 @@ class WineDetailViewController: UIViewController, UIScrollViewDelegate, Firebase
reviewView.noReviewLabel.isHidden = false
} else {
// 리뷰가 있을 때
reviewView.moreBtn.isHidden = false
reviewView.reviewCollectionView.isHidden = false
reviewView.scoreLabel.isHidden = false
reviewView.noReviewLabel.isHidden = true
Expand Down Expand Up @@ -348,11 +347,6 @@ class WineDetailViewController: UIViewController, UIScrollViewDelegate, Firebase

let tastingNoteString = noseNotes.joined(separator: ", ")

DispatchQueue.main.async { [weak self] in
//self.setupNavigationBar() // 제목 및 좋아요 설정
self?.updateReviewView()
}

let infoData = WineDetailInfoModel(
wineName:wineResponse.name,
rating:wineResponse.vivinoRating,
Expand Down Expand Up @@ -402,6 +396,7 @@ class WineDetailViewController: UIViewController, UIScrollViewDelegate, Firebase
self.wineDetailsView.configure(infoData)

self.averageTastingNoteView.configure(avgData, self.vintage)
self.updateReviewView()
self.reviewView.configure(reviewData)
self.reviewView.reviewCollectionView.reloadData()
}
Expand Down
Loading