Skip to content

Commit

Permalink
[Network] #91 - 게시물에 해당하는 답글 조회 API 뷰컨에 연결 완료
Browse files Browse the repository at this point in the history
  • Loading branch information
boogios committed Jan 17, 2024
1 parent 2661909 commit d26e17e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class PostReplyCollectionViewCell: UICollectionViewCell, UICollectionViewR
return view
}()

private let profileImageView: UIImageView = {
let profileImageView: UIImageView = {
let image = UIImageView()
image.contentMode = .scaleAspectFill
image.clipsToBounds = true
Expand All @@ -39,15 +39,15 @@ final class PostReplyCollectionViewCell: UICollectionViewCell, UICollectionViewR
return image
}()

private let nicknameLabel: UILabel = {
let nicknameLabel: UILabel = {
let label = UILabel()
label.textColor = .donBlack
label.text = "Don't be야 사랑해~"
label.font = .font(.body3)
return label
}()

private let transparentLabel: UILabel = {
let transparentLabel: UILabel = {
let label = UILabel()
label.textColor = .donGray9
label.text = "투명도 0%"
Expand All @@ -63,21 +63,21 @@ final class PostReplyCollectionViewCell: UICollectionViewCell, UICollectionViewR
return label
}()

private let timeLabel: UILabel = {
let timeLabel: UILabel = {
let label = UILabel()
label.textColor = .donGray9
label.text = "3분 전"
label.font = .font(.caption4)
return label
}()

private let kebabButton: UIButton = {
let kebabButton: UIButton = {
let button = UIButton()
button.setImage(ImageLiterals.Posting.btnKebab, for: .normal)
return button
}()

private let contentTextLabel: UILabel = {
let contentTextLabel: UILabel = {
let label = UILabel()
label.textColor = .donBlack
label.text = "돈비를 사용하면 진짜 돈비를 맞을 수 있나요? 저 돈비 맞고 싶어요 돈벼락이 최고입니다. 돈비를 사용하면 진짜 돈비를 맞을 수 있나요? 저 돈비 맞고 싶어요 돈벼락이 최고입니다."
Expand All @@ -101,7 +101,7 @@ final class PostReplyCollectionViewCell: UICollectionViewCell, UICollectionViewR
return button
}()

private let likeNumLabel: UILabel = {
let likeNumLabel: UILabel = {
let label = UILabel()
label.textColor = .donGray11
label.text = "54"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,16 +305,24 @@ extension PostViewController {

extension PostViewController {
private func getAPI() {
let input = PostViewModel.Input(viewUpdate: Just((contentId)).eraseToAnyPublisher())
let input = PostViewModel.Input(viewUpdate: Just((contentId)).eraseToAnyPublisher(), collectionViewUpdata: Just((contentId)).eraseToAnyPublisher())

let output = viewModel.transform(from: input, cancelBag: cancelBag)

output.getPostData
.receive(on: RunLoop.main)
.sink { data in
print(data)
self.bindPostData(data: data)
}
.store(in: self.cancelBag)

output.getPostReplyData
.receive(on: RunLoop.main)
.sink { data in
self.postReplyCollectionView.reloadData()
}
.store(in: self.cancelBag)
}

private func bindPostData(data: PostDetailResponseDTO) {
Expand All @@ -340,18 +348,21 @@ extension PostViewController: UICollectionViewDelegate { }

extension PostViewController: UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
5
let sortedData = viewModel.postReplyData.sorted {
$0.time.compare($1.time, options: .numeric) == .orderedDescending
}

viewModel.postReplyData = sortedData
return viewModel.postReplyData.count
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell =
PostReplyCollectionViewCell.dequeueReusableCell(collectionView: collectionView, indexPath: indexPath)
cell.alarmTriggerType = "commentGhost"
// cell.targetMemberId = viewModel.postData[indexPath.row].memberId
// cell.alarmTriggerdId = viewModel.postData[indexPath.row].contentId
cell.targetMemberId = 7
cell.alarmTriggerdId = 15
if self.memberId == loadUserData()?.memberId {
cell.targetMemberId = viewModel.postReplyData[indexPath.row].memberId
cell.alarmTriggerdId = self.contentId
if viewModel.postReplyData[indexPath.row].memberId == loadUserData()?.memberId {
cell.ghostButton.isHidden = true
cell.verticalTextBarView.isHidden = true
} else {
Expand All @@ -371,6 +382,13 @@ extension PostViewController: UICollectionViewDataSource {
self.alarmTriggerdId = cell.alarmTriggerdId
self.present(self.transparentPopupVC, animated: false, completion: nil)
}
cell.nicknameLabel.text = viewModel.postReplyData[indexPath.row].memberNickname
cell.transparentLabel.text = "투명도 \(viewModel.postReplyData[indexPath.row].memberGhost)%"
cell.contentTextLabel.text = viewModel.postReplyData[indexPath.row].commentText
cell.likeNumLabel.text = "\(viewModel.postReplyData[indexPath.row].commentLikedNumber)"
cell.timeLabel.text = "\(viewModel.postReplyData[indexPath.row].time.formattedTime())"
cell.profileImageView.load(url: "\(viewModel.postReplyData[indexPath.row].memberProfileUrl)")


return cell
}
Expand Down

0 comments on commit d26e17e

Please sign in to comment.