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
68 changes: 40 additions & 28 deletions DE/DE/Sources/Core/CommonUI/View/AverageTastingNoteView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@ import Then
import DesignSystem

public class AverageTastingNoteView: UIView {
private let title = TitleWithoutBarView(title: "Tasting Note", subTitle: "테이스팅 노트")
public let writeNewTastingNoteBtn = TextIconButton(title: "작성하러 가기")

private lazy var noTastinNote = UILabel().then {
$0.text = "작성된 테이스팅 노트가 없습니다."
$0.textColor = AppColor.gray70
$0.font = UIFont.pretendard(.regular, size: 14)
private let tastingNoteContentView = UIView()
private let noTastingNote = UILabel().then {
$0.isHidden = true
}

private let title = TitleWithoutBarView(title: "Tasting Note", subTitle: "테이스팅 노트")
public let writeNewTastingNoteBtn = TextIconButton(title: "작성하러 가기")

private let nose = UILabel()
private let palate = UILabel()
public lazy var noseContents = UILabel()
Expand All @@ -36,10 +33,16 @@ public class AverageTastingNoteView: UIView {
}

private func setupUI() {
addSubviews(title, writeNewTastingNoteBtn, nose, palate, noseContents, palateContents, noTastinNote)
addSubviews(title, writeNewTastingNoteBtn, tastingNoteContentView, noTastingNote)
tastingNoteContentView.addSubviews(nose, palate, noseContents, palateContents)

AppTextStyle.KR.body2.apply(to: nose, text: "Nose", color: AppColor.gray50)
AppTextStyle.KR.body2.apply(to: palate, text: "Palate", color: AppColor.gray50)
AppTextStyle.KR.body2.apply(
to: noTastingNote,
text: "작성된 테이스팅 노트가 없습니다.",
color: AppColor.gray70
)

[noseContents, palateContents].forEach {
$0.numberOfLines = 0
Expand All @@ -59,9 +62,20 @@ public class AverageTastingNoteView: UIView {
$0.trailing.equalTo(safeAreaLayoutGuide)
}

nose.snp.makeConstraints {
tastingNoteContentView.snp.makeConstraints {
$0.top.equalTo(title.snp.bottom).offset(10)
$0.horizontalEdges.equalToSuperview()
$0.bottom.equalToSuperview().inset(24)
}

noTastingNote.snp.makeConstraints {
$0.top.equalTo(title.snp.bottom).offset(10)
$0.leading.equalToSuperview()
$0.bottom.equalToSuperview().inset(24)
}

nose.snp.makeConstraints {
$0.top.leading.equalToSuperview()
}

noseContents.snp.makeConstraints {
Expand All @@ -79,32 +93,30 @@ public class AverageTastingNoteView: UIView {
$0.top.equalTo(palate.snp.top)
$0.leading.equalTo(palate.snp.trailing).offset(27)
$0.trailing.lessThanOrEqualToSuperview()
$0.bottom.equalToSuperview().inset(24)
$0.bottom.equalToSuperview()
}

noTastinNote.snp.makeConstraints {
$0.top.equalTo(title.snp.bottom).offset(10)
$0.leading.equalToSuperview()
$0.bottom.equalToSuperview().inset(24)
}
}

public func configure(_ model: WineAverageTastingNoteModel) {
if model.avgAcidity == 0.0 {
nose.isHidden = true
palate.isHidden = true
noseContents.isHidden = true
palateContents.isHidden = true
[nose, palate, noseContents, palateContents].forEach { view in
view.removeFromSuperview()
}
noTastinNote.isHidden = false
} else {
[title, writeNewTastingNoteBtn, nose, palate, noseContents, palateContents].forEach{ self.addSubview($0) }

public func configure(_ model: WineAverageTastingNoteModel, _ vintage: Int?) {
let hasContent = (vintage != nil) && !model.wineNoseText.isEmpty

tastingNoteContentView.isHidden = !hasContent
noTastingNote.isHidden = hasContent

if hasContent {
AppTextStyle.KR.body3.apply(to: noseContents, text: model.wineNoseText, color: AppColor.gray100)
AppTextStyle.KR.body3.apply(to: palateContents, text: "\(model.sugarContentDescription()), \(model.acidityDescription()), \(model.tanninDescription()), \(model.bodyDescription()), \(model.alcoholDescription())", color: AppColor.gray100)

AppTextStyle.KR.body2.apply(to: noTastingNote, text: "", color: AppColor.gray70)
} else {
AppTextStyle.KR.body3.apply(to: noseContents, text: "", color: AppColor.gray100)
AppTextStyle.KR.body3.apply(to: palateContents, text: "", color: AppColor.gray100)

let message = (vintage == nil) ? "빈티지를 선택해 주세요." : "작성된 테이스팅 노트가 없습니다."
AppTextStyle.KR.body2.apply(to: noTastingNote, text: message, color: AppColor.gray70)
}

self.layoutIfNeeded()
}
}
2 changes: 1 addition & 1 deletion DE/DE/Sources/Core/CommonUI/View/VintageInfoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class VintageInfoView: UIView {
public init() {
super.init(frame: .zero)
setupLayout()
configure(with: "1970")
configure(with: "빈티지 선택")
}

required init?(coder: NSCoder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class WineDetailViewController: UIViewController, UIScrollViewDelegate, Firebase
AppTextStyle.KR.head.apply(to: largeTitleLabel, text: wineName, color: AppColor.black)
}
}
var vintage: Int? = nil
var wineInfoForTN : WineDetailInfoModel?

var isLiked: Bool = false {
Expand Down Expand Up @@ -50,6 +51,7 @@ class WineDetailViewController: UIViewController, UIScrollViewDelegate, Firebase
super.viewWillAppear(animated)
self.view.addSubview(indicator)
self.navigationController?.setNavigationBarHidden(false, animated: animated)

callWineDetailAPI(wineId: self.wineId)
}

Expand Down Expand Up @@ -94,6 +96,27 @@ class WineDetailViewController: UIViewController, UIScrollViewDelegate, Firebase
)
}

private func addButtonTarget() {
averageTastingNoteView.writeNewTastingNoteBtn.addTarget(self, action: #selector(goToTastingNote), for: .touchUpInside)
reviewView.moreBtn.addTarget(self, action: #selector(goToEntireReview), for: .touchUpInside)

vintageInfoView.tabAction = { [weak self] in
let vc = VintageTableViewController()

vc.onYearSelected = { [weak self] year in
guard let self = self else { return }

self.vintageInfoView.configure(with: "\(year)")

if year != self.vintage {
self.vintage = year
self.callWineDetailAPI(wineId: self.wineId)
}
}
self?.navigationController?.pushViewController(vc, animated: true)
}
}

private func showLiked() {
DispatchQueue.main.async {
if let rightButton = self.navigationItem.rightBarButtonItem?.customView as? UIButton {
Expand Down Expand Up @@ -164,16 +187,6 @@ class WineDetailViewController: UIViewController, UIScrollViewDelegate, Firebase
let divider3 = DividerFactory.make()
let thinDivider = DividerFactory.make()

private func addButtonTarget() {
averageTastingNoteView.writeNewTastingNoteBtn.addTarget(self, action: #selector(goToTastingNote), for: .touchUpInside)
reviewView.moreBtn.addTarget(self, action: #selector(goToEntireReview), for: .touchUpInside)
vintageInfoView.tabAction = { [weak self] in
let vc = VintageTableViewController()
vc.hidesBottomBarWhenPushed = true
self?.navigationController?.pushViewController(vc, animated: true)
}
}

@objc
private func goToTastingNote() {
// 배정이 안되서 일단 비활성화 해둠!!
Expand All @@ -188,14 +201,21 @@ class WineDetailViewController: UIViewController, UIScrollViewDelegate, Firebase
return
}

guard let vintageYear = vintage else {
self.showToastMessage(message: "빈티지를 선택해주세요.", yPosition: view.frame.height * 0.75)
return
}

TNWineDataManager.shared.updateWineData(wineId: self.wineId,
wineName: self.wineName,
vintage: vintageYear,
sort: wineInfo.sort,
country: wineInfo.country,
region: wineInfo.region,
imageUrl: wineInfo.image,
variety: wineInfo.variety
)

navigationController?.pushViewController(vc, animated: true)
}

Expand All @@ -206,6 +226,7 @@ class WineDetailViewController: UIViewController, UIScrollViewDelegate, Firebase
let vc = EntireReviewViewController()
vc.wineId = self.wineId
vc.wineName = self.wineName
vc.vintage = self.vintage
navigationController?.pushViewController(vc, animated: true)
}

Expand Down Expand Up @@ -310,6 +331,11 @@ class WineDetailViewController: UIViewController, UIScrollViewDelegate, Firebase
self.wineName = wineResponse.name
self.isLiked = wineResponse.liked
self.originalIsLiked = wineResponse.liked

if let vintageYear = wineResponse.vintageYear {
self.vintage = vintageYear
}

let noseNotes = [
wineResponse.nose1,
wineResponse.nose2,
Expand All @@ -323,12 +349,36 @@ class WineDetailViewController: UIViewController, UIScrollViewDelegate, Firebase
self?.updateReviewView()
}

let infoData = WineDetailInfoModel(wineName:wineResponse.name, rating:wineResponse.vivinoRating, image: wineResponse.imageUrl, sort: wineResponse.sort, country: wineResponse.country, region: wineResponse.region, variety: wineResponse.variety)
let infoData = WineDetailInfoModel(
wineName:wineResponse.name,
rating:wineResponse.vivinoRating,
image: wineResponse.imageUrl,
sort: wineResponse.sort,
country: wineResponse.country,
region: wineResponse.region,
variety: wineResponse.variety
)

if let year = self.vintage {
self.vintageInfoView.configure(with: "\(year)")
} else {
self.vintageInfoView.configure(with: "빈티지 선택")
}

let rateData = WineViVinoRatingModel(vivinoRating: wineResponse.vivinoRating)
let avgData = WineAverageTastingNoteModel(wineNoseText: tastingNoteString, avgSugarContent: wineResponse.avgSweetness, avgAcidity: wineResponse.avgAcidity, avgTannin: wineResponse.avgTannin, avgBody: wineResponse.avgBody, avgAlcohol: wineResponse.avgAlcohol)

let avgData = WineAverageTastingNoteModel(
wineNoseText: tastingNoteString,
avgSugarContent: wineResponse.avgSweetness,
avgAcidity: wineResponse.avgAcidity,
avgTannin: wineResponse.avgTannin,
avgBody: wineResponse.avgBody,
avgAlcohol: wineResponse.avgAlcohol
)

let roundedAvgMemberRating = (wineResponse.avgMemberRating * 10).rounded() / 10
let reviewData = WineAverageReviewModel(avgMemberRating: roundedAvgMemberRating)

let reviewData = WineAverageReviewModel(avgMemberRating: roundedAvgMemberRating)
if let reviewResponse = responseData.recentReviews {
for data in reviewResponse {
if let name = data.name,
Expand All @@ -346,7 +396,8 @@ class WineDetailViewController: UIViewController, UIScrollViewDelegate, Firebase
self.wineInfoForTN = infoData // 테이스팅 노트 작성을 위한 데이터 저장
self.wineInfoView.configure(infoData)
self.wineDetailsView.configure(infoData)
self.averageTastingNoteView.configure(avgData)

self.averageTastingNoteView.configure(avgData, self.vintage)
self.reviewView.configure(reviewData)
self.reviewView.reviewCollectionView.reloadData()
}
Expand All @@ -358,7 +409,7 @@ class WineDetailViewController: UIViewController, UIScrollViewDelegate, Firebase
do {
let responseData = try await wineNetworkService.fetchWineInfo(
wineId: wineId,
vintageYear: nil
vintageYear: vintage
)
DispatchQueue.main.async {
self.reviewData.removeAll()
Expand All @@ -378,7 +429,10 @@ class WineDetailViewController: UIViewController, UIScrollViewDelegate, Firebase
func callLikeAPI(wineId: Int) async {
self.view.showBlockingView()
do {
let _ = try await likedNetworkService.postWishlist(wineId: wineId)
let _ = try await likedNetworkService.postWishlist(
wineId: wineId,
vintageYear: vintage
)
self.view.hideBlockingView()
} catch {
self.view.hideBlockingView()
Expand All @@ -389,7 +443,10 @@ class WineDetailViewController: UIViewController, UIScrollViewDelegate, Firebase
func calldeleteLikedAPI(wineId: Int) async {
self.view.showBlockingView()
do {
let _ = try await likedNetworkService.deleteWishlist(wineId: wineId)
let _ = try await likedNetworkService.deleteWishlist(
wineId: wineId,
vintageYear: vintage
)
self.view.hideBlockingView()
} catch {
self.view.hideBlockingView()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class TNWineDataManager {

var wineId: Int
var wineName: String
var vintage: Int
var sort: String
var country: String
var region: String
Expand All @@ -18,6 +19,7 @@ class TNWineDataManager {
public init(
wineId: Int = 0,
wineName: String = "",
vintage: Int = 0,
sort: String = "",
country: String = "",
region: String = "",
Expand All @@ -26,6 +28,7 @@ class TNWineDataManager {
) {
self.wineId = wineId
self.wineName = wineName
self.vintage = vintage
self.sort = sort
self.country = country
self.region = region
Expand All @@ -37,6 +40,7 @@ class TNWineDataManager {
func updateWineData(
wineId: Int? = nil,
wineName: String? = nil,
vintage: Int? = nil,
sort: String? = nil,
country: String? = nil,
region: String? = nil,
Expand All @@ -45,6 +49,7 @@ class TNWineDataManager {
) {
if let wineId = wineId { self.wineId = wineId }
if let wineName = wineName { self.wineName = wineName }
if let vintage = vintage { self.vintage = vintage }
if let sort = sort { self.sort = sort }
if let country = country { self.country = country }
if let region = region { self.region = region }
Expand All @@ -55,6 +60,7 @@ class TNWineDataManager {
func resetData() {
wineId = 0
wineName = ""
vintage = 0
sort = ""
country = ""
region = ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class TNWineDetailViewController: UIViewController, UIScrollViewDelegate, Fireba
AppTextStyle.KR.head.apply(to: largeTitleLabel, text: wineName, color: AppColor.black)
}
}
var vintage: Int? = nil
let wineData = TNWineDataManager.shared
let tnManager = NewTastingNoteManager.shared

Expand Down Expand Up @@ -247,7 +248,7 @@ class TNWineDetailViewController: UIViewController, UIScrollViewDelegate, Fireba
DispatchQueue.main.async {
self.wineInfoView.configure(infoData)
self.wineDetailsView.configure(infoData)
self.averageTastingNoteView.configure(avgData)
self.averageTastingNoteView.configure(avgData, self.vintage)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ public class ChooseWineColorViewController: UIViewController, FirebaseTrackable

public override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
colorView.header.setTitleLabel(title: wineData.wineName)

let fullName = "\(wineData.wineName) \(wineData.vintage)"
colorView.header.setTitleLabel(title: fullName)
self.navigationController?.setNavigationBarHidden(false, animated: animated)

colorView.infoView.image.sd_setImage(with: URL(string: wineData.imageUrl))
colorView.infoView.countryContents.text = wineData.country + ", " + wineData.region
colorView.infoView.kindContents.text = wineData.sort
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public class NoseTestVC: UIViewController, UIScrollViewDelegate, FirebaseTrackab
}
}

topView.header.setTitleLabel(title: wineData.wineName,
let fullName = "\(wineData.wineName) \(wineData.vintage)"
topView.header.setTitleLabel(title: fullName,
titleStyle: AppTextStyle.KR.subtitle1,
titleColor: AppColor.purple100,
description: despText,
Expand Down
Loading
Loading