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] 커뮤니티 글 리스트 클릭 후 뒤로 돌아왔을 때 전체 글로 reload 되는 버그 해결하기 #515

Merged
merged 3 commits into from
Oct 10, 2022
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
10 changes: 5 additions & 5 deletions NadoSunbae-iOS/NadoSunbae-iOS/Global/Struct/PostFilterType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

import Foundation

enum PostFilterType: CaseIterable {
case community
case general
case questionToEveryone // 전체에게 질문 (커뮤니티 질문)
case information
enum PostFilterType: Int, CaseIterable {
case community = 0
case general = 1
case questionToEveryone = 2 // 전체에게 질문 (커뮤니티 질문)
case information = 3
case questionToPerson // 1:1 질문
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@ final class CommunityMainVC: BaseVC, View {
registerCell()
setUpDelegate()
bindCommunityTV()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
setUpInitAction()
setUpSegmentAction(type: PostFilterType(rawValue: communitySegmentedControl.selectedSegmentIndex) ?? .community)
}

func bind(reactor: CommunityMainReactor) {
Expand Down Expand Up @@ -109,6 +105,7 @@ extension CommunityMainVC {
.subscribe(onNext: {
self.navigator?.instantiateVC(destinationViewControllerType: CommunityWriteVC.self, useStoryboard: false, storyboardName: "", naviType: .present, modalPresentationStyle: .fullScreen) { communityWriteVC in
communityWriteVC.reactor = CommunityWriteReactor()
communityWriteVC.sendPostTypeDelegate = self
}
})
.disposed(by: disposeBag)
Expand Down Expand Up @@ -174,10 +171,6 @@ extension CommunityMainVC {
.disposed(by: disposeBag)
}

private func setUpInitAction() {
reactor?.action.onNext(.reloadCommunityTV(majorID: 0, type: .community, sort: "recent", search: ""))
}

/// CommunityTV를 bind하는 메서드
private func bindCommunityTV() {
communityTV.rx.modelSelected(PostListResModel.self)
Expand Down Expand Up @@ -262,6 +255,11 @@ extension CommunityMainVC {
communityTV.rx.setDelegate(self)
.disposed(by: disposeBag)
}

/// segment Action을 설정하는 메서드
private func setUpSegmentAction(type: PostFilterType) {
reactor?.action.onNext(.reloadCommunityTV(type: type))
}
}

// MARK: - UITableViewDelegate
Expand All @@ -277,3 +275,12 @@ extension CommunityMainVC: UITableViewDelegate {
return UITableView.automaticDimension
}
}

// MARK: - SendUpdateModalDelegate
extension CommunityMainVC: SendUpdateModalDelegate {
func sendUpdate(data: Any) {
let postFilterType = data as? PostFilterType
communitySegmentedControl.selectedSegmentIndex = postFilterType?.rawValue ?? 0
setUpSegmentAction(type: postFilterType ?? .community)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ final class CommunityWriteVC: BaseWritePostVC, View {
var categoryIndex: Int?
var originTitle: String?
var originContent: String?
var sendPostTypeDelegate: SendUpdateModalDelegate?

// MARK: Life Cycle
override func viewDidLoad() {
Expand Down Expand Up @@ -196,9 +197,11 @@ extension CommunityWriteVC {

reactor.state
.map{ $0.writePostSuccess }
.subscribe(onNext: { success in
.subscribe(onNext: { [weak self] success in
if success {
self.dismiss(animated: true, completion: nil)
self?.dismiss(animated: true, completion: {
self?.sendPostTypeDelegate?.sendUpdate(data: (self?.selectedCategory ?? .community) as PostFilterType)
})
}
})
.disposed(by: disposeBag)
Expand Down