Skip to content

Commit

Permalink
✅ Chore: 1:1 질문 관련 TVC 코드들 BaseQuestionTVC로 통일 (#542)
Browse files Browse the repository at this point in the history
  • Loading branch information
hwangJi-dev committed Oct 19, 2022
1 parent f32217f commit c5bb58c
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ extension RecentQuestionTVC {
.map { $0.questionList }
.bind(to: recentQuestionTV.rx.items) { tableView, index, item in
let indexPath = IndexPath(row: index, section: 0)
let cell = tableView.dequeueReusableCell(withIdentifier: QuestionTVC.className, for: indexPath)
let cell = tableView.dequeueReusableCell(withIdentifier: BaseQuestionTVC.className, for: indexPath)

guard let questionCell = cell as? BaseQuestionTVC else { return UITableViewCell() }
questionCell.setEssentialCellInfo(data: item)
questionCell.removeBottomSeparator(isLast: tableView.isLast(for: indexPath))

guard let questionCell = cell as? QuestionTVC else { return UITableViewCell() }
questionCell.setPostData(data: item)
return questionCell
}
.disposed(by: self.disposeBag)
Expand Down Expand Up @@ -94,7 +96,7 @@ extension RecentQuestionTVC {

/// 셀 등록 메서드
private func registerCell() {
recentQuestionTV.register(QuestionTVC.self, forCellReuseIdentifier: QuestionTVC.className)
recentQuestionTV.register(BaseQuestionTVC.self, forCellReuseIdentifier: BaseQuestionTVC.className)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,12 @@ extension PersonalQuestionVC: View {
.map { $0.recentQuestionList }
.bind(to: recentQuestionTV.rx.items) { tableView, index, item in
let indexPath = IndexPath(row: index, section: 0)
let cell = tableView.dequeueReusableCell(withIdentifier: QuestionTVC.className, for: indexPath)
let cell = tableView.dequeueReusableCell(withIdentifier: BaseQuestionTVC.className, for: indexPath)

guard let questionCell = cell as? BaseQuestionTVC else { return UITableViewCell() }
questionCell.setEssentialCellInfo(data: item)
questionCell.removeBottomSeparator(isLast: tableView.isLast(for: indexPath))

guard let questionCell = cell as? QuestionTVC else { return UITableViewCell() }
questionCell.setPostData(data: item)
return questionCell
}
.disposed(by: self.disposeBag)
Expand Down Expand Up @@ -214,7 +216,7 @@ extension PersonalQuestionVC {
private func registerCell() {
availableQuestionPersonCV.register(AvailableQuestionPersonCVC.self, forCellWithReuseIdentifier: AvailableQuestionPersonCVC.className)
availableQuestionPersonCV.register(SeeMoreQuestionPersonCVC.self, forCellWithReuseIdentifier: SeeMoreQuestionPersonCVC.className)
recentQuestionTV.register(QuestionTVC.self, forCellReuseIdentifier: QuestionTVC.className)
recentQuestionTV.register(BaseQuestionTVC.self, forCellReuseIdentifier: BaseQuestionTVC.className)
}

/// 대리자 위임 메서드
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ final class HomeRecentPersonalQuestionVC: BaseVC {
private let questionTV = UITableView().then {
$0.layer.cornerRadius = 16
$0.layer.borderColor = UIColor.gray0.cgColor
$0.layer.borderWidth = 1
$0.isScrollEnabled = false
$0.separatorInset = UIEdgeInsets(top: 0, left: 16, bottom: 0, right: 16)
$0.separatorColor = .gray0
Expand All @@ -48,7 +49,7 @@ final class HomeRecentPersonalQuestionVC: BaseVC {
questionTV.delegate = self
questionTV.dataSource = self

questionTV.register(EntireQuestionListTVC.self, forCellReuseIdentifier: EntireQuestionListTVC.className)
questionTV.register(BaseQuestionTVC.self, forCellReuseIdentifier: BaseQuestionTVC.className)
}

private func updateQuestionTVHeight() {
Expand All @@ -67,8 +68,8 @@ extension HomeRecentPersonalQuestionVC: UITableViewDataSource {
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: EntireQuestionListTVC.className, for: indexPath) as? EntireQuestionListTVC else { return EntireQuestionListTVC() }
cell.setPostData(data: questionList[indexPath.row])
guard let cell = tableView.dequeueReusableCell(withIdentifier: BaseQuestionTVC.className, for: indexPath) as? BaseQuestionTVC else { return BaseQuestionTVC() }
cell.setEssentialCellInfo(data: questionList[indexPath.row])
cell.layoutSubviews()
cell.removeBottomSeparator(isLast: tableView.isLast(for: indexPath))
return cell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class MypageLikeListVC: BaseVC {
likeListTV.delegate = self
likeListTV.register(UINib(nibName: ReviewMainPostTVC.className, bundle: nil), forCellReuseIdentifier: ReviewMainPostTVC.className)
likeListTV.register(CommunityTVC.self, forCellReuseIdentifier: CommunityTVC.className)
likeListTV.register(EntireQuestionListTVC.self, forCellReuseIdentifier: EntireQuestionListTVC.className)
likeListTV.register(BaseQuestionTVC.self, forCellReuseIdentifier: BaseQuestionTVC.className)
}

private func updateLikeListTVUI() {
Expand Down Expand Up @@ -214,15 +214,15 @@ extension MypageLikeListVC: UITableViewDataSource {
cell.tagImgList = reviewData[indexPath.row].tagList
return cell
case .personalQuestion:
guard let cell = tableView.dequeueReusableCell(withIdentifier: EntireQuestionListTVC.className, for: indexPath) as? EntireQuestionListTVC else { return EntireQuestionListTVC() }
cell.setMypageLikeData(data: questionToPersonData[indexPath.row])
guard let cell = tableView.dequeueReusableCell(withIdentifier: BaseQuestionTVC.className, for: indexPath) as? BaseQuestionTVC else { return BaseQuestionTVC() }
cell.setEssentialMypageLikeCellInfo(data: questionToPersonData[indexPath.row])
cell.layoutSubviews()
return cell
case .community:
guard let cell = tableView.dequeueReusableCell(withIdentifier: CommunityTVC.className, for: indexPath) as? CommunityTVC else { return CommunityTVC() }

let data = communityData[indexPath.row]
cell.setCommunityData(data: PostListResModel(postID: data.id, type: data.type, title: data.title, content: data.content, createdAt: data.createdAt, majorName: data.majorName, writer: CommunityWriter(writerID: data.writer.id, nickname: data.writer.nickname), isAuthorized: true, commentCount: data.commentCount, like: data.like))
cell.setEssentialCommunityCellInfo(data: PostListResModel(postID: data.id, type: data.type, title: data.title, content: data.content, createdAt: data.createdAt, majorName: data.majorName, writer: CommunityWriter(writerID: data.writer.id, nickname: data.writer.nickname), isAuthorized: true, commentCount: data.commentCount, like: data.like))
return cell
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extension MypageMainVC: UITableViewDataSource {
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: BaseQuestionTVC.className, for: indexPath) as? BaseQuestionTVC else { return UITableViewCell() }
let questionData = self.questionList[indexPath.row]
cell.setPostData(data: PostListResModel(postID: questionData.postID, type: nil, title: questionData.title, content: questionData.content, createdAt: questionData.createdAt, majorName: "", writer: questionData.writer, isAuthorized: false, commentCount: questionData.commentCount, like: questionData.like))
cell.setEssentialCellInfo(data: PostListResModel(postID: questionData.postID, type: nil, title: questionData.title, content: questionData.content, createdAt: questionData.createdAt, majorName: "", writer: questionData.writer, isAuthorized: false, commentCount: questionData.commentCount, like: questionData.like))
cell.layoutIfNeeded()

return cell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class MypagePostListVC: BaseVC {
postListTV.delegate = self

postListTV.register(CommunityTVC.self, forCellReuseIdentifier: CommunityTVC.className)
postListTV.register(EntireQuestionListTVC.self, forCellReuseIdentifier: EntireQuestionListTVC.className)
postListTV.register(BaseQuestionTVC.self, forCellReuseIdentifier: BaseQuestionTVC.className)

postListTV.removeSeparatorsOfEmptyCellsAndLastCell()
}
Expand Down Expand Up @@ -146,30 +146,32 @@ extension MypagePostListVC: UITableViewDataSource {
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if isPostOrAnswer {
if isPersonalQuestionOrCommunity {
guard let cell = tableView.dequeueReusableCell(withIdentifier: EntireQuestionListTVC.className, for: indexPath) as? EntireQuestionListTVC else { return EntireQuestionListTVC() }
cell.setPostData(data: personalQuestionData[indexPath.row])
guard let cell = tableView.dequeueReusableCell(withIdentifier: BaseQuestionTVC.className, for: indexPath) as? BaseQuestionTVC else { return BaseQuestionTVC() }
cell.setEssentialCellInfo(data: personalQuestionData[indexPath.row])

cell.layoutSubviews()
cell.removeBottomSeparator(isLast: tableView.isLast(for: indexPath))
return cell
} else {
guard let cell = tableView.dequeueReusableCell(withIdentifier: CommunityTVC.className, for: indexPath) as? CommunityTVC else { return CommunityTVC() }
cell.setCommunityData(data: communityData[indexPath.row])
cell.setEssentialCommunityCellInfo(data: communityData[indexPath.row])
cell.removeBottomSeparator(isLast: tableView.isLast(for: indexPath))
return cell
}
} else {
if isPersonalQuestionOrCommunity {
guard let cell = tableView.dequeueReusableCell(withIdentifier: EntireQuestionListTVC.className, for: indexPath) as? EntireQuestionListTVC else { return EntireQuestionListTVC() }
guard let cell = tableView.dequeueReusableCell(withIdentifier: BaseQuestionTVC.className, for: indexPath) as? BaseQuestionTVC else { return BaseQuestionTVC() }
let data = personalQuestionDataForAnswer[indexPath.row]
// TODO: MypageResModel에도 isAuthorized값 넣어달라고 요청하기.
cell.setPostData(data: PostListResModel(postID: data.id, type: data.type, title: data.title, content: data.content, createdAt: data.createdAt, majorName: data.majorName, writer: CommunityWriter(writerID: data.writer.id, nickname: data.writer.nickname), isAuthorized: true, commentCount: data.commentCount, like: data.like))
cell.setEssentialCellInfo(data: PostListResModel(postID: data.id, type: data.type, title: data.title, content: data.content, createdAt: data.createdAt, majorName: data.majorName, writer: CommunityWriter(writerID: data.writer.id, nickname: data.writer.nickname), isAuthorized: true, commentCount: data.commentCount, like: data.like))

cell.layoutSubviews()
cell.removeBottomSeparator(isLast: tableView.isLast(for: indexPath))
return cell
} else {
guard let cell = tableView.dequeueReusableCell(withIdentifier: CommunityTVC.className, for: indexPath) as? CommunityTVC else { return CommunityTVC() }
let data = communityDataForAnswer[indexPath.row]
cell.setCommunityData(data: PostListResModel(postID: data.id, type: data.type, title: data.title, content: data.content, createdAt: data.createdAt, majorName: data.majorName, writer: CommunityWriter(writerID: data.writer.id, nickname: data.writer.nickname), isAuthorized: true, commentCount: data.commentCount, like: data.like))
cell.setEssentialCommunityCellInfo(data: PostListResModel(postID: data.id, type: data.type, title: data.title, content: data.content, createdAt: data.createdAt, majorName: data.majorName, writer: CommunityWriter(writerID: data.writer.id, nickname: data.writer.nickname), isAuthorized: true, commentCount: data.commentCount, like: data.like))
cell.removeBottomSeparator(isLast: tableView.isLast(for: indexPath))
return cell
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extension MypageUserVC: UITableViewDataSource {
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = BaseQuestionTVC()
let questionData = self.questionList[indexPath.row]
cell.setPostData(data: PostListResModel(postID: questionData.postID, type: nil, title: questionData.title, content: questionData.content, createdAt: questionData.createdAt, majorName: "", writer: questionData.writer, isAuthorized: false, commentCount: questionData.commentCount, like: questionData.like))
cell.setEssentialCellInfo(data: PostListResModel(postID: questionData.postID, type: nil, title: questionData.title, content: questionData.content, createdAt: questionData.createdAt, majorName: "", writer: questionData.writer, isAuthorized: false, commentCount: questionData.commentCount, like: questionData.like))
cell.layoutIfNeeded()

return cell
Expand Down
Loading

0 comments on commit c5bb58c

Please sign in to comment.