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

게시글 옵션 클릭시 바텀시트 띄우기 #366

Merged
merged 9 commits into from
May 12, 2023
21 changes: 19 additions & 2 deletions PLUB/Sources/Views/Home/Clipboard/BoardDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ final class BoardDetailViewController: BaseViewController {
}
.disposed(by: disposeBag)

viewModel.showBottomSheetObservable
viewModel.showCommentBottomSheetObservable
.subscribe(with: self) { owner, tuple in
let bottomSheetVC = CommentOptionBottomSheetViewController(commentID: tuple.commentID, userAccessType: tuple.userType).then {
$0.delegate = owner
Expand Down Expand Up @@ -157,6 +157,15 @@ final class BoardDetailViewController: BaseViewController {
owner.commentInputView.endEditing(true)
}
.disposed(by: disposeBag)

viewModel.showBoardBottomSheetObservable
.subscribe(with: self) { owner, tuple in
let (accessType, isPinned) = tuple
let viewController = BoardBottomSheetViewController(accessType: accessType, isPinned: isPinned)
viewController.delegate = owner
owner.present(viewController, animated: true)
}
.disposed(by: disposeBag)
}
}

Expand Down Expand Up @@ -194,7 +203,15 @@ extension BoardDetailViewController: CommentOptionBottomSheetDelegate {
}

func reportButtonTapped(commentID: Int) {
print(#function)
PLUBToast.makeToast(text: "commentID: \(commentID) report tapped")
}
}

// MARK: - BoardBottomSheetDelegate

extension BoardDetailViewController: BoardBottomSheetDelegate {
func selectedBoardSheetType(type: BoardBottomSheetType) {
PLUBToast.makeToast(text: "\(type)")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ protocol BoardDetailViewModelType: BoardDetailViewModel {
/// decoratorView에 들어갈 적절한 text를 처리합니다.
var decoratorNameObserable: Observable<(labelText: String, buttonText: String)> { get }

var showBottomSheetObservable: Observable<(commentID: Int, userType: CommentOptionBottomSheetViewController.UserAccessType)> { get }
var showCommentBottomSheetObservable: Observable<(commentID: Int, userType: CommentOptionBottomSheetViewController.UserAccessType)> { get }

var showBoardBottomSheetObservable: Observable<(BoardBottomSheetViewController.AccessType, Bool)> { get }
}

protocol FeedLikeDelegate: AnyObject {
Expand Down Expand Up @@ -84,15 +86,17 @@ final class BoardDetailViewModel {

// MARK: Subjects

private let collectionViewSubject = PublishSubject<UICollectionView>()
private let commentInputSubject = PublishSubject<String>()
private let editCommentTextSubject = PublishSubject<String>()
private let decoratorNameSubject = PublishSubject<(labelText: String, buttonText: String)>()
private let bottomCellSubject = PublishSubject<(collectionViewHeight: CGFloat, offset: CGFloat)>()
private let showBottomSheetSubject = PublishSubject<(commentID: Int, userType: CommentOptionBottomSheetViewController.UserAccessType)>()
private let targetIDSubject = BehaviorSubject<Int?>(value: nil)
private let deleteIDSubject = PublishSubject<Int>()
private let commentOptionSubject = BehaviorSubject<CommentOption>(value: .commentOrReply)
private let collectionViewSubject = PublishSubject<UICollectionView>()
private let commentInputSubject = PublishSubject<String>()
private let editCommentTextSubject = PublishSubject<String>()
private let decoratorNameSubject = PublishSubject<(labelText: String, buttonText: String)>()
private let bottomCellSubject = PublishSubject<(collectionViewHeight: CGFloat, offset: CGFloat)>()
private let showCommentBottomSheetSubject = PublishSubject<(commentID: Int, userType: CommentOptionBottomSheetViewController.UserAccessType)>()
private let boardBottomSheetParameterSubject = ReplaySubject<(BoardBottomSheetViewController.AccessType, Bool)>.create(bufferSize: 1)
private let boardOptionTappedSubject = PublishSubject<Void>()
private let targetIDSubject = BehaviorSubject<Int?>(value: nil)
private let deleteIDSubject = PublishSubject<Int>()
private let commentOptionSubject = BehaviorSubject<CommentOption>(value: .commentOrReply)

// MARK: - Initializations

Expand Down Expand Up @@ -144,6 +148,17 @@ extension BoardDetailViewModel {
if let like = tuple.feed.isLike {
owner.boardLike = like
}

let accessType: BoardBottomSheetViewController.AccessType
if tuple.feed.isAuthor {
accessType = .author
} else if tuple.feed.isHost {
accessType = .host
} else {
accessType = .normal
}
owner.boardBottomSheetParameterSubject.onNext((accessType, tuple.feed.isPinned))

owner.comments.formUnion(tuple.comments) // 댓글 삽입
owner.setCollectionView(tuple.collectionView, content: tuple.feed.toBoardModel)
owner.applyInitialSnapshots()
Expand Down Expand Up @@ -324,8 +339,13 @@ extension BoardDetailViewModel: BoardDetailViewModelType {
decoratorNameSubject.asObservable()
}

var showBottomSheetObservable: Observable<(commentID: Int, userType: CommentOptionBottomSheetViewController.UserAccessType)> {
showBottomSheetSubject.asObservable()
var showCommentBottomSheetObservable: Observable<(commentID: Int, userType: CommentOptionBottomSheetViewController.UserAccessType)> {
showCommentBottomSheetSubject.asObservable()
}

var showBoardBottomSheetObservable: Observable<(BoardBottomSheetViewController.AccessType, Bool)> {
boardOptionTappedSubject
.withLatestFrom(boardBottomSheetParameterSubject)
}
}

Expand Down Expand Up @@ -452,7 +472,7 @@ extension BoardDetailViewModel: BoardDetailCollectionHeaderViewDelegate {
}

func didTappedSettingButton() {
PLUBToast.makeToast(text: "Setting Button Tapped")
boardOptionTappedSubject.onNext(Void())
}
}

Expand Down Expand Up @@ -487,7 +507,7 @@ extension BoardDetailViewModel: BoardDetailCollectionViewCellDelegate {
accessType = .normal
}

showBottomSheetSubject.onNext((commentID, accessType))
showCommentBottomSheetSubject.onNext((commentID, accessType))
}
}

Expand Down
2 changes: 1 addition & 1 deletion PLUB/Sources/Views/Home/MainPage/BoardViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ final class BoardViewController: BaseViewController {

if gestureRecognizer.state == .began {
// 롱 프레스 터치가 시작될 떄
let bottomSheet = BoardBottomSheetViewController()
let bottomSheet = BoardBottomSheetViewController(accessType: .normal, isPinned: false)
bottomSheet.delegate = self
present(bottomSheet, animated: true)
} else if gestureRecognizer.state == .ended {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,73 @@ enum BoardBottomSheetType {

final class BoardBottomSheetViewController: BottomSheetViewController {

// MARK: - Properties

weak var delegate: BoardBottomSheetDelegate?

private let accessType: AccessType
private let isPinned: Bool

// MARK: - UI Components

private let contentStackView = UIStackView().then {
$0.axis = .vertical
$0.spacing = 8
}

private let clipboardFixView = BottomSheetListView(text: "클립보드에 고정", image: "pinBlack")
private let modifyBoardView = BottomSheetListView(text: "게시글 수정", image: "editBlack")
private let reportBoardView = BottomSheetListView(text: "게시글 신고", image: "lightBeaconMain")
private let deleteBoardView = BottomSheetListView(text: "게시글 삭제", image: "trashRed", textColor: .error)
private lazy var clipboardFixView = BottomSheetListView(
text: isPinned ? "클립보드 고정 해제" : "클립보드에 고정",
image: "pinBlack"
)
private lazy var modifyBoardView = BottomSheetListView(text: "게시글 수정", image: "editBlack")
private lazy var reportBoardView = BottomSheetListView(text: "게시글 신고", image: "lightBeaconMain")
private lazy var deleteBoardView = BottomSheetListView(text: "게시글 삭제", image: "trashRed", textColor: .error)


// MARK: - Initializations

init(accessType: AccessType, isPinned: Bool) {
self.accessType = accessType
self.isPinned = isPinned
super.init(nibName: nil, bundle: nil)
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

// MARK: - Configurations

override func setupLayouts() {
super.setupLayouts()
contentView.addSubview(contentStackView)

[clipboardFixView, modifyBoardView, reportBoardView, deleteBoardView].forEach {
contentStackView.addArrangedSubview($0)
if accessType != .normal {
contentStackView.addArrangedSubview(clipboardFixView)
}

if accessType == .author {
contentStackView.addArrangedSubview(modifyBoardView)
contentStackView.addArrangedSubview(deleteBoardView)
} else {
contentStackView.addArrangedSubview(reportBoardView)
}
}

override func setupConstraints() {
super.setupConstraints()

[clipboardFixView, modifyBoardView, reportBoardView, deleteBoardView].forEach {
$0.snp.makeConstraints {
$0.height.equalTo(Metrics.Size.listHeight)
}
let heightConstraint: (ConstraintMaker) -> Void = { $0.height.equalTo(Metrics.Size.listHeight) }

if accessType != .normal {
clipboardFixView.snp.makeConstraints(heightConstraint)
}

if accessType == .author {
modifyBoardView.snp.makeConstraints(heightConstraint)
deleteBoardView.snp.makeConstraints(heightConstraint)
} else {
reportBoardView.snp.makeConstraints(heightConstraint)
}

contentStackView.snp.makeConstraints {
Expand All @@ -63,28 +102,48 @@ final class BoardBottomSheetViewController: BottomSheetViewController {

override func bind() {
super.bind()
clipboardFixView.button.rx.tap
.subscribe(with: self) { owner, _ in
owner.delegate?.selectedBoardSheetType(type: .fix)
}
.disposed(by: disposeBag)
if accessType != .normal {
clipboardFixView.button.rx.tap
.subscribe(with: self) { owner, _ in
owner.delegate?.selectedBoardSheetType(type: .fix)
}
.disposed(by: disposeBag)
}

if accessType == .author {
modifyBoardView.button.rx.tap
.subscribe(with: self) { owner, _ in
owner.delegate?.selectedBoardSheetType(type: .modify)
}
.disposed(by: disposeBag)

deleteBoardView.button.rx.tap
.subscribe(with: self) { owner, _ in
owner.delegate?.selectedBoardSheetType(type: .delete)
}
.disposed(by: disposeBag)
} else {
reportBoardView.button.rx.tap
.subscribe(with: self) { owner, _ in
owner.delegate?.selectedBoardSheetType(type: .report)
}
.disposed(by: disposeBag)
}
}
}

// MARK: - Enum Type

extension BoardBottomSheetViewController {
enum AccessType {

modifyBoardView.button.rx.tap
.subscribe(with: self) { owner, _ in
owner.delegate?.selectedBoardSheetType(type: .modify)
}
.disposed(by: disposeBag)
/// 호스트
case host

reportBoardView.button.rx.tap
.subscribe(with: self) { owner, _ in
owner.delegate?.selectedBoardSheetType(type: .report)
}
.disposed(by: disposeBag)
/// 게시글 저자
case author

deleteBoardView.button.rx.tap
.subscribe(with: self) { owner, _ in
owner.delegate?.selectedBoardSheetType(type: .delete)
}
.disposed(by: disposeBag)
/// 일반
case normal
}
}