Skip to content

Commit 3f8e189

Browse files
authored
[Feature] 계정, 게시글 차단하기 구현 (#53)
2 parents 542d3a3 + 1cd1c48 commit 3f8e189

File tree

7 files changed

+254
-24
lines changed

7 files changed

+254
-24
lines changed

Fitfty/Projects/Coordinator/Sources/Profile/PostCoordinator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private extension PostCoordinator {
103103
coordinator.finishDelegate = self
104104
coordinator.parentCoordinator = self
105105
let bottomSheetViewController = BottomSheetViewController(
106-
style: .custom(196),
106+
style: .custom(383),
107107
contentViewController: coordinator.navigationController
108108
)
109109
coordinator.bottomSheetDelegate = bottomSheetViewController

Fitfty/Projects/Coordinator/Sources/Profile/ProfileCoordinator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private extension ProfileCoordinator {
9797
coordinator.parentCoordinator = self
9898
let bottomSheetViewController =
9999
BottomSheetViewController(
100-
style: .small,
100+
style: .custom(196),
101101
contentViewController: coordinator.navigationController
102102
)
103103
coordinator.bottomSheetDelegate = bottomSheetViewController

Fitfty/Projects/Coordinator/Sources/Profile/ReportCoordinator.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Foundation
1010
import UIKit
1111
import Profile
1212
import Common
13+
import Core
1314

1415
final class ReportCoordinator: Coordinator {
1516

@@ -53,6 +54,12 @@ private extension ReportCoordinator {
5354
func makeReportViewController(reportPresentType: ReportPresentType, userToken: String?, boardToken: String?) -> UIViewController {
5455
let viewController = ReportViewController(
5556
coordinator: self,
57+
viewModel: ReportViewModel(
58+
userManager: DefaultUserManager.shared,
59+
userToken: userToken,
60+
boardToken: boardToken,
61+
fitftyRepository: DefaultFitftyRepository()
62+
),
5663
reportPresentType: reportPresentType,
5764
userToken: userToken,
5865
boardToken: boardToken
@@ -91,6 +98,15 @@ extension ReportCoordinator: ReportCoordinatorInterface {
9198
self.finishDelegate?.coordinatorDidFinish(childCoordinator: self)
9299
}
93100
}
101+
102+
func popToRoot() {
103+
bottomSheetDelegate?.dismissBottomSheet {
104+
self.navigationController.viewControllers.removeAll()
105+
self.finishDelegate?.coordinatorDidFinish(childCoordinator: self)
106+
self.parentCoordinator?.navigationController.popToRootViewController(animated: true)
107+
}
108+
}
109+
94110
}
95111

96112
extension ReportCoordinator: CoordinatorFinishDelegate {

Fitfty/Projects/Profile/Sources/CoordinatorInterfaces/ReportCoordinatorInterface.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ public protocol ReportCoordinatorInterface: AnyObject {
1313

1414
func showDetailReport(_ reportType: ReportType, userToken: String?, boardToken: String?)
1515
func dismiss()
16+
func popToRoot()
1617

1718
}

Fitfty/Projects/Profile/Sources/Post/Views/MyPostBottomSheetView.swift

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,43 +27,93 @@ final class MyPostBottomSheetView: UIStackView {
2727
return button
2828
}()
2929

30-
private lazy var seperatorView: UIView = {
30+
private lazy var thirdButton: UIButton = {
31+
let button = UIButton()
32+
button.setTitleColor(CommonAsset.Colors.gray07.color, for: .normal)
33+
button.titleLabel?.font = FitftyFont.appleSDSemiBold(size: 18).font
34+
button.contentHorizontalAlignment = .left
35+
return button
36+
}()
37+
38+
private lazy var fourthButton: UIButton = {
39+
let button = UIButton()
40+
button.setTitleColor(CommonAsset.Colors.gray07.color, for: .normal)
41+
button.titleLabel?.font = FitftyFont.appleSDSemiBold(size: 18).font
42+
button.contentHorizontalAlignment = .left
43+
return button
44+
}()
45+
46+
private lazy var seperatorView1: UIView = {
47+
let view = UIView()
48+
view.backgroundColor = CommonAsset.Colors.gray01.color
49+
return view
50+
}()
51+
52+
private lazy var seperatorView2: UIView = {
53+
let view = UIView()
54+
view.backgroundColor = CommonAsset.Colors.gray01.color
55+
return view
56+
}()
57+
58+
private lazy var seperatorView3: UIView = {
3159
let view = UIView()
3260
view.backgroundColor = CommonAsset.Colors.gray01.color
3361
return view
3462
}()
3563

3664
override init(frame: CGRect) {
3765
super.init(frame: frame)
38-
setConstraintsLayout()
66+
setStackView()
3967
}
4068

4169
required init(coder: NSCoder) {
4270
fatalError("init(coder:) has not been implemented")
4371
}
4472

4573
private func setConstraintsLayout() {
74+
addArrangedSubviews(firstButton, seperatorView1, secondButton)
75+
NSLayoutConstraint.activate([
76+
seperatorView1.heightAnchor.constraint(equalToConstant: 1)
77+
])
78+
}
79+
80+
private func setStackView() {
4681
self.axis = .vertical
4782
self.distribution = .fill
4883
self.spacing = 24
49-
addArrangedSubviews(firstButton, seperatorView, secondButton)
50-
NSLayoutConstraint.activate([
51-
seperatorView.heightAnchor.constraint(equalToConstant: 1)
52-
])
5384
}
85+
5486
}
5587

5688
extension MyPostBottomSheetView {
5789

5890
func setUpMyPost() {
5991
firstButton.setTitle("게시글 수정", for: .normal)
6092
secondButton.setTitle("게시글 삭제", for: .normal)
93+
setConstraintsLayout()
6194
}
6295

6396
func setUpUserPost() {
6497
firstButton.setTitleColor(CommonAsset.Colors.error.color, for: .normal)
6598
firstButton.setTitle("계정 신고", for: .normal)
6699
secondButton.setTitle("게시글 신고", for: .normal)
100+
thirdButton.setTitle("이 게시글 차단하기", for: .normal)
101+
fourthButton.setTitle("이 계정 차단하기", for: .normal)
102+
addArrangedSubviews(firstButton, seperatorView1, secondButton, seperatorView2,
103+
thirdButton, seperatorView3, fourthButton)
104+
NSLayoutConstraint.activate([
105+
seperatorView1.heightAnchor.constraint(equalToConstant: 1),
106+
seperatorView2.heightAnchor.constraint(equalToConstant: 1),
107+
seperatorView3.heightAnchor.constraint(equalToConstant: 1)
108+
])
109+
}
110+
111+
func setUpUserProfile() {
112+
firstButton.setTitleColor(CommonAsset.Colors.error.color, for: .normal)
113+
secondButton.setTitleColor(CommonAsset.Colors.gray07.color, for: .normal)
114+
firstButton.setTitle("계정 신고", for: .normal)
115+
secondButton.setTitle("이 계정 차단하기", for: .normal)
116+
setConstraintsLayout()
67117
}
68118

69119
func setActionFirstButton(_ target: Any?, action: Selector) {
@@ -74,4 +124,12 @@ extension MyPostBottomSheetView {
74124
secondButton.addTarget(target, action: action, for: .touchUpInside)
75125
}
76126

127+
func setActionThirdButton( _ target: Any?, action: Selector) {
128+
thirdButton.addTarget(target, action: action, for: .touchUpInside)
129+
}
130+
131+
func setActionFourthButton( _ target: Any?, action: Selector) {
132+
fourthButton.addTarget(target, action: action, for: .touchUpInside)
133+
}
134+
77135
}

Fitfty/Projects/Profile/Sources/Report/ViewControllers/ReportViewController.swift

Lines changed: 62 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88

99
import UIKit
1010
import Common
11+
import Combine
1112

1213
final public class ReportViewController: UIViewController {
1314

14-
let coordinator: ReportCoordinatorInterface
15-
let reportPresentType: ReportPresentType
16-
var userToken: String?
17-
var boardToken: String?
15+
private let coordinator: ReportCoordinatorInterface
16+
private let viewModel: ReportViewModel
17+
private var cancellables: Set<AnyCancellable> = .init()
18+
19+
private let reportPresentType: ReportPresentType
20+
private var userToken: String?
21+
private var boardToken: String?
1822

1923
private lazy var userReportButton: UIButton = {
2024
let button = UIButton()
@@ -36,15 +40,18 @@ final public class ReportViewController: UIViewController {
3640
public override func viewDidLoad() {
3741
super.viewDidLoad()
3842
setUp()
43+
bind()
3944
}
4045

4146
public init(
4247
coordinator: ReportCoordinatorInterface,
48+
viewModel: ReportViewModel,
4349
reportPresentType: ReportPresentType,
4450
userToken: String?,
4551
boardToken: String?
4652
) {
4753
self.coordinator = coordinator
54+
self.viewModel = viewModel
4855
self.reportPresentType = reportPresentType
4956
self.userToken = userToken
5057
self.boardToken = boardToken
@@ -60,29 +67,60 @@ final public class ReportViewController: UIViewController {
6067

6168
}
6269

70+
func bind() {
71+
viewModel.state.compactMap { $0 }
72+
.sinkOnMainThread(receiveValue: { [weak self] state in
73+
switch state {
74+
case .errorMessage(let message):
75+
self?.showAlert(message: message)
76+
77+
case .completed(let completed):
78+
guard completed else {
79+
return
80+
}
81+
self?.coordinator.popToRoot()
82+
}
83+
}).store(in: &cancellables)
84+
}
85+
6386
private func setConstraintsLayout() {
87+
view.addSubviews(myPostBottomSheetView)
88+
NSLayoutConstraint.activate([
89+
myPostBottomSheetView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20),
90+
myPostBottomSheetView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20),
91+
myPostBottomSheetView.topAnchor.constraint(equalTo: view.topAnchor, constant: 40)
92+
])
6493
switch reportPresentType {
6594
case .userReport:
66-
view.addSubviews(userReportButton)
67-
NSLayoutConstraint.activate([
68-
userReportButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20),
69-
userReportButton.topAnchor.constraint(equalTo: view.topAnchor, constant: 44),
70-
userReportButton.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20)
71-
])
95+
myPostBottomSheetView.setUpUserProfile()
96+
myPostBottomSheetView.setActionFirstButton(self, action: #selector(didTapUserReportButton))
97+
myPostBottomSheetView.setActionSecondButton(self, action: #selector(didTapUserBlockButton))
98+
7299
case .postUserReport:
73-
view.addSubviews(myPostBottomSheetView)
74-
NSLayoutConstraint.activate([
75-
myPostBottomSheetView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 20),
76-
myPostBottomSheetView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -20),
77-
myPostBottomSheetView.topAnchor.constraint(equalTo: view.topAnchor, constant: 40)
78-
])
79100
myPostBottomSheetView.setUpUserPost()
80101
myPostBottomSheetView.setActionFirstButton(self, action: #selector(didTapUserReportButton))
81102
myPostBottomSheetView.setActionSecondButton(self, action: #selector(didTapPostReportButton))
103+
myPostBottomSheetView.setActionThirdButton(self, action: #selector(didTapPostBlockButton))
104+
myPostBottomSheetView.setActionFourthButton(self, action: #selector(didTapUserBlockButton))
82105
}
83106

84107
}
85108

109+
private func showBlockAlert(_ reportType: ReportType) {
110+
let message = reportType == .userReport ? "계정" : "게시글"
111+
let alert = UIAlertController(title: "정말 이 \(message)을 차단할까요?", message: nil, preferredStyle: .alert)
112+
alert.addAction(UIAlertAction(title: "취소", style: .default))
113+
alert.addAction(UIAlertAction(title: "차단하기", style: .default, handler: { _ in
114+
switch reportType {
115+
case .userReport:
116+
self.viewModel.input.didTapBlockButton(.userReport)
117+
case .postReport:
118+
self.viewModel.input.didTapBlockButton(.postReport)
119+
}
120+
}))
121+
present(alert, animated: true)
122+
}
123+
86124
@objc func didTapUserReportButton(_ sender: Any?) {
87125
coordinator.showDetailReport(.userReport, userToken: userToken, boardToken: boardToken)
88126
}
@@ -91,4 +129,12 @@ final public class ReportViewController: UIViewController {
91129
coordinator.showDetailReport(.postReport, userToken: userToken, boardToken: boardToken)
92130
}
93131

132+
@objc func didTapUserBlockButton(_ sender: Any?) {
133+
showBlockAlert(.userReport)
134+
}
135+
136+
@objc func didTapPostBlockButton(_ sender: Any?) {
137+
showBlockAlert(.postReport)
138+
}
139+
94140
}

0 commit comments

Comments
 (0)