Skip to content

Commit

Permalink
[FIX] ArticleDetail 북마크 버튼 재사용 이슈 해결 (Team-LionHeart#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
ffalswo2 committed Jul 21, 2023
1 parent 67f05c7 commit bcc3762
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,16 @@ private extension ThumnailTableViewCell {
}

extension ThumnailTableViewCell {
func setThumbnailImageView() {
bookMarkButton.isHidden = false
gradientImageView.isHidden = false
}

func setImageTypeCell() {
imageCaptionLabel.snp.updateConstraints { make in
make.bottom.equalToSuperview().inset(72)
}
gradientImageView.isHidden = true
bookMarkButton.isHidden = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,15 @@ final class ArticleDetailViewController: UIViewController {

// MARK: - Properties

private var isBookMarked: Bool?

private var articleDatas: [BlockTypeAppData]? {
didSet {
self.articleTableView.reloadData()
hideLoading()
}
}

// private var articleDatas: [BlockTypeAppData] = ArticleDetail.dummy().toAppData()

private var isArticleMarked: Bool?

private var articleId: Int?

private var contentOffsetY: CGFloat = 0
Expand Down Expand Up @@ -91,6 +89,7 @@ extension ArticleDetailViewController {
do {
let bookmarkRequest = BookmarkRequest(articleId: articleId, bookmarkStatus: isSelected)
try await BookmarkService.shared.postBookmark(bookmarkRequest)
isBookMarked = isSelected
} catch {
guard let error = error as? NetworkError else { return }
self.handleError(error)
Expand Down Expand Up @@ -191,19 +190,24 @@ extension ArticleDetailViewController: UITableViewDataSource {

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let articleDatas else { return UITableViewCell() }

switch articleDatas[indexPath.row] {
case .thumbnail(let isMarked, let thumbnailModel):
let cell = ThumnailTableViewCell.dequeueReusableCell(to: articleTableView)
self.isArticleMarked = isMarked
cell.isMarked = self.isArticleMarked
cell.inputData = thumbnailModel

cell.selectionStyle = .none
cell.bookmarkButtonDidTap = { isSelected in
guard let articleId = self.articleId else { return }

self.articleBookMark(articleId: articleId, isSelected: isSelected)
}

if let isBookMarked {
cell.isMarked = isBookMarked
} else {
cell.isMarked = isMarked
}
cell.setThumbnailImageView()
return cell
case .articleTitle(let titleModel):
let cell = TitleTableViewCell.dequeueReusableCell(to: articleTableView)
Expand Down

0 comments on commit bcc3762

Please sign in to comment.