Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix [#174] 전체적인 페이징 커서 값 오류 해결, 앰플리튜드 오류 해결 #175

Merged
merged 7 commits into from
Mar 29, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ final class HomeViewController: UIViewController {
}

override func viewWillDisappear(_ animated: Bool) {
refreshCollectionViewDidDrag()

self.navigationController?.navigationBar.isHidden = false
self.navigationController?.navigationBar.backgroundColor = .clear

Expand Down Expand Up @@ -154,7 +152,6 @@ extension HomeViewController {
deletePostBottomsheetView.dimView.removeFromSuperview()
deletePostBottomsheetView.bottomsheetView.removeFromSuperview()
}
refreshCollectionViewDidDrag()
}

func showDeletePostPopupView() {
Expand All @@ -179,7 +176,6 @@ extension HomeViewController {
warnUserBottomsheetView.dimView.removeFromSuperview()
warnUserBottomsheetView.bottomsheetView.removeFromSuperview()
}
refreshCollectionViewDidDrag()
}

func showWarnUserSafariView() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

코드 리뷰:
1. viewWillDisappear 및 showDeletePostPopupView, showWarnUserSafariView 함수에서 호출되던 refreshCollectionViewDidDrag()이 중복 제거되었는데 이것은 기능적으로 올바른 결정일 수 있습니다.
2. 그러나 refreshCollectionViewDidDrag()가 두 번째 함수에서 필요로 하는 상황이나 타이밍에 따라 조정이 필요할 수 있습니다.
3. 만약 refreshCollectionViewDidDrag()를 특정 순간에만 호출해야 한다면 호출 방식을 조정하여 코드의 명확성을 높일 수 있습니다.
4. 코드 리팩토링을 통해 중복을 제거하고 호출되는 시점을 명확히하는 것이 좋을 수 있습니다.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,15 @@ extension HomeViewModel {
} else {
var tempArrayData: [PostDataResponseDTO] = []

for content in data {
tempArrayData.append(content)
if data.isEmpty {
self.cursor = -1
} else {
for content in data {
tempArrayData.append(content)
}
self.postData = tempArrayData
postDatas.append(contentsOf: postData)
}
self.postData = tempArrayData
postDatas.append(contentsOf: postData)
}
}
return result

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

주어진 코드 패치를 간략한 코드 리뷰로 확인해보겠습니다.

  1. Bug risks(버그 위험):
  • func 작성에 대한 주석이 없습니다.
  • postDatas와 postData가 서로 다른 변수로 보입니다. self.postDatapostDatas.append(contentsOf: postData)에서 postData 변수는 정확히 정의되지 않았습니다.
  1. 개선 제안:
  • tempArrayData를 사용하는 대신 self.postData에 바로 추가하는 것이 더 효율적일 수 있습니다.
  • self.postData에 값이 있는 경우에만 postDatas에 추가하는 것이 더 안전할 수 있습니다.
  • 코드 가독성을 높이기 위해 if-else 블록 내의 들여쓰기를 유지하고 일관된 형식을 유지할 필요가 있습니다.

이러한 사항들을 고려하여 소스 코드를 조정하면 좋을 것 같습니다.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,6 @@ extension MyPageContentViewController: UICollectionViewDelegate { }

extension MyPageContentViewController: UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if self.contentDatas.count == 0 {
firstContentButton.isHidden = false
} else {
firstContentButton.isHidden = true
}
return self.contentDatas.count
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ final class MyPageViewController: UIViewController {
private lazy var sixthReason = self.transparentReasonView.sixthReasonView.radioButton.publisher(for: .touchUpInside).map { _ in }.eraseToAnyPublisher()

var memberId: Int = loadUserData()?.memberId ?? 0
var memberProfileImage: String = loadUserData()?.userProfileImage ?? ""
var contentId: Int = 0
var alarmTriggerType: String = ""
var targetMemberId: Int = 0
Expand Down Expand Up @@ -122,8 +123,10 @@ final class MyPageViewController: UIViewController {
bindHomeViewModel()
setNotification()

DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
self.refreshData()
if loadUserData()?.userProfileImage != self.memberProfileImage {
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
self.refreshData()
}
}

let image = ImageLiterals.MyPage.icnMenu
Expand Down Expand Up @@ -254,6 +257,8 @@ extension MyPageViewController {
@objc
func refreshData() {
DispatchQueue.main.async {
self.contentCursor = -1
self.commentCursor = -1
self.bindViewModel()
}
self.perform(#selector(self.finishedRefreshing), with: nil, afterDelay: 0.1)
Expand Down Expand Up @@ -355,11 +360,23 @@ extension MyPageViewController {
.receive(on: RunLoop.main)
.sink { data in
self.rootView.myPageContentViewController.contentDatas = data
self.viewModel.contentCursor = self.contentCursor
if data.isEmpty {
self.viewModel.contentCursor = -1
} else {
self.viewModel.contentCursor = self.contentCursor
}
if !data.isEmpty {
self.rootView.myPageContentViewController.noContentLabel.isHidden = true
self.rootView.myPageContentViewController.firstContentButton.isHidden = true
} else {
self.rootView.myPageContentViewController.noContentLabel.isHidden = false
if loadUserData()?.memberId != self.memberId {
self.rootView.myPageContentViewController.noContentLabel.isHidden = false
self.rootView.myPageContentViewController.firstContentButton.isHidden = true
} else {
self.rootView.myPageContentViewController.noContentLabel.isHidden = false
self.rootView.myPageContentViewController.firstContentButton.isHidden = false
}
}
DispatchQueue.main.async {
self.rootView.myPageContentViewController.homeCollectionView.reloadData()
Expand Down Expand Up @@ -468,7 +485,6 @@ extension MyPageViewController {
if data.memberId != loadUserData()?.memberId ?? 0 {
self.rootView.myPageContentViewController.noContentLabel.text = "아직 \(data.nickname)" + StringLiterals.MyPage.myPageNoContentOtherLabel
self.rootView.myPageCommentViewController.noCommentLabel.text = "아직 \(data.nickname)" + StringLiterals.MyPage.myPageNoCommentOtherLabel
self.rootView.myPageContentViewController.firstContentButton.isHidden = true
} else {
self.rootView.myPageContentViewController.noContentLabel.text = "\(data.nickname)" + StringLiterals.MyPage.myPageNoContentLabel
self.rootView.myPageCommentViewController.noCommentLabel.text = StringLiterals.MyPage.myPageNoCommentLabel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,15 @@ extension MyPageViewModel {
} else {
var tempArrayData: [MyPageMemberContentResponseDTO] = []

for content in data {
tempArrayData.append(content)
if data.isEmpty {
self.contentCursor = -1
} else {
for content in data {
tempArrayData.append(content)
}
self.myPageContentData = tempArrayData
myPageContentDatas.append(contentsOf: myPageContentData)
}
self.myPageContentData = tempArrayData
myPageContentDatas.append(contentsOf: myPageContentData)
}
}
return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ final class PostDetailViewController: UIViewController {
setTextFieldGesture()
setRefreshControll()
setLayout()
refreshPostDidDrag()
refreshControl.beginRefreshing()
}

init(viewModel: PostDetailViewModel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,23 @@ final class PostDetailViewModel: ViewModelType {
let postReplyResult = try await
self.getPostReplyDataAPI(accessToken: accessToken, contentId: value)
if let data = postReplyResult?.data {
if let lastCommentId = data.last?.commentId {
self.cursor = lastCommentId
}
if self.cursor == -1 {
self.postReplyDatas = []

self.postReplyData = data
self.getPostReplyData.send(data)

postReplyDatas.append(contentsOf: postReplyData)
} else {
self.postReplyData = data
self.getPostReplyData.send(data)

postReplyDatas.append(contentsOf: postReplyData)
}
}
postReplyDatas.append(contentsOf: postReplyData)
}
} catch {
print(error)
Expand Down