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

댓글 수정 기능 구현 #303

Merged
merged 12 commits into from
Apr 20, 2023
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
14 changes: 9 additions & 5 deletions PLUB.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
70F1DFEA297D992100F9BC83 /* RecruitmentService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70F1DFE9297D992100F9BC83 /* RecruitmentService.swift */; };
70F1DFEF297D9E1C00F9BC83 /* DetailRecruitmentViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70F1DFEE297D9E1C00F9BC83 /* DetailRecruitmentViewModel.swift */; };
70F1DFF1297DA3CE00F9BC83 /* DetailRecruitmentModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70F1DFF0297DA3CE00F9BC83 /* DetailRecruitmentModel.swift */; };
BA034D3229E864CA003B7192 /* ReplyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA034D3129E864CA003B7192 /* ReplyView.swift */; };
BA034D3229E864CA003B7192 /* CommentOptionDecoratorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA034D3129E864CA003B7192 /* CommentOptionDecoratorView.swift */; };
BA117A3B297440B500B37E03 /* UserDefaultsWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA117A3A297440B500B37E03 /* UserDefaultsWrapper.swift */; };
BA117A3D297440D900B37E03 /* UserManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA117A3C297440D900B37E03 /* UserManager.swift */; };
BA117A4E297444EE00B37E03 /* KakaoSDKAuth in Frameworks */ = {isa = PBXBuildFile; productRef = BA117A4D297444EE00B37E03 /* KakaoSDKAuth */; };
Expand Down Expand Up @@ -169,6 +169,7 @@
BA5D9EDB29E406AD00F06AB5 /* Day.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA5D9EDA29E406AD00F06AB5 /* Day.swift */; };
BA5DEB302974D8E200650788 /* NetworkResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA5DEB2F2974D8E200650788 /* NetworkResult.swift */; };
BA5DEB3329751E5F00650788 /* GoogleSignIn in Frameworks */ = {isa = PBXBuildFile; productRef = BA5DEB3229751E5F00650788 /* GoogleSignIn */; };
BA5EC6C629EFD4E5000A68B7 /* EditCommentUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA5EC6C529EFD4E5000A68B7 /* EditCommentUseCase.swift */; };
BA6D7C5329A7D46900D8E928 /* CommentsRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA6D7C5229A7D46900D8E928 /* CommentsRequest.swift */; };
BA7255C12992445600A3E8F5 /* PLUBTabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA7255C02992445600A3E8F5 /* PLUBTabBarController.swift */; };
BA72BCF029BB03FF007165E5 /* BaseNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BA72BCEF29BB03FF007165E5 /* BaseNavigationController.swift */; };
Expand Down Expand Up @@ -483,7 +484,7 @@
70F1DFE9297D992100F9BC83 /* RecruitmentService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecruitmentService.swift; sourceTree = "<group>"; };
70F1DFEE297D9E1C00F9BC83 /* DetailRecruitmentViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailRecruitmentViewModel.swift; sourceTree = "<group>"; };
70F1DFF0297DA3CE00F9BC83 /* DetailRecruitmentModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailRecruitmentModel.swift; sourceTree = "<group>"; };
BA034D3129E864CA003B7192 /* ReplyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReplyView.swift; sourceTree = "<group>"; };
BA034D3129E864CA003B7192 /* CommentOptionDecoratorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentOptionDecoratorView.swift; sourceTree = "<group>"; };
BA117A3A297440B500B37E03 /* UserDefaultsWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefaultsWrapper.swift; sourceTree = "<group>"; };
BA117A3C297440D900B37E03 /* UserManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserManager.swift; sourceTree = "<group>"; };
BA1BEDC2296454AB00C6BD41 /* ProfileViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -534,6 +535,7 @@
BA5D9ED829E3F16900F06AB5 /* ArchiveContent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArchiveContent.swift; sourceTree = "<group>"; };
BA5D9EDA29E406AD00F06AB5 /* Day.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Day.swift; sourceTree = "<group>"; };
BA5DEB2F2974D8E200650788 /* NetworkResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkResult.swift; sourceTree = "<group>"; };
BA5EC6C529EFD4E5000A68B7 /* EditCommentUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = EditCommentUseCase.swift; path = PLUB/Sources/UseCases/Feeds/EditCommentUseCase.swift; sourceTree = SOURCE_ROOT; };
BA6D7C5229A7D46900D8E928 /* CommentsRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentsRequest.swift; sourceTree = "<group>"; };
BA7255C02992445600A3E8F5 /* PLUBTabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PLUBTabBarController.swift; sourceTree = "<group>"; };
BA72BCEF29BB03FF007165E5 /* BaseNavigationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseNavigationController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1244,9 +1246,10 @@
BA4CCDF429EAB91D0040D0D7 /* Feeds */ = {
isa = PBXGroup;
children = (
BAB2E56B29E30A13006B7BDC /* PostCommentUseCase.swift */,
BA57F3F529ED30D200A9F790 /* DeleteCommentUseCase.swift */,
BA5EC6C529EFD4E5000A68B7 /* EditCommentUseCase.swift */,
BAB2E56D29E30F96006B7BDC /* GetCommentsUseCase.swift */,
BAB2E56B29E30A13006B7BDC /* PostCommentUseCase.swift */,
);
path = Feeds;
sourceTree = "<group>";
Expand Down Expand Up @@ -1564,7 +1567,7 @@
children = (
BAB033F929B5C5580077C4D9 /* BoardDetailCollectionHeaderView.swift */,
BAC9794429CF0E9E00A5DF1B /* CommentInputView.swift */,
BA034D3129E864CA003B7192 /* ReplyView.swift */,
BA034D3129E864CA003B7192 /* CommentOptionDecoratorView.swift */,
BA4CCDF029EA79EA0040D0D7 /* CommentOptionBottomSheetViewController.swift */,
);
path = Component;
Expand Down Expand Up @@ -2255,7 +2258,7 @@
70A4209C2988B1DC0026E9F9 /* SortControl.swift in Sources */,
BA5D9EDB29E406AD00F06AB5 /* Day.swift in Sources */,
70A420A7298D0F140026E9F9 /* RecentSearchListCollectionViewCell.swift in Sources */,
BA034D3229E864CA003B7192 /* ReplyView.swift in Sources */,
BA034D3229E864CA003B7192 /* CommentOptionDecoratorView.swift in Sources */,
C3E0390A29C2125700C4744C /* InquireApplicantResponse.swift in Sources */,
C3B3435629BE3A2200935B73 /* MyPageService.swift in Sources */,
C36F31C729E3072800AC2C8A /* ScheduleBottomSheetViewController.swift in Sources */,
Expand Down Expand Up @@ -2368,6 +2371,7 @@
BA8E2B46297467A2009DDF32 /* AuthService.swift in Sources */,
BAC923DF29546BF500385841 /* BirthViewController.swift in Sources */,
C3EC027D29D9582D0024C962 /* WaitingViewController.swift in Sources */,
BA5EC6C629EFD4E5000A68B7 /* EditCommentUseCase.swift in Sources */,
70A420B329914B370026E9F9 /* SubCategoryListResponse.swift in Sources */,
BA88125228E48A2F00BD832A /* HomeViewController.swift in Sources */,
BA340E2529782356002BAF2C /* ProfileViewController.swift in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion PLUB/Sources/Models/Feeds/CommentContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct CommentContent: Codable {
let commentID: Int

/// 댓글 내용
let content: String
var content: String

/// 프로필 이미지 URL
let profileImageURL: String?
Expand Down
19 changes: 19 additions & 0 deletions PLUB/Sources/UseCases/Feeds/EditCommentUseCase.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// EditCommentUseCase.swift
// PLUB
//
// Created by 홍승현 on 2023/04/19.
//

import RxSwift

protocol EditCommentUseCase {
func execute(plubbingID: Int, feedID: Int, commentID: Int, content: String) -> Observable<CommentContent>
}

final class DefaultEditCommentUseCase: EditCommentUseCase {

func execute(plubbingID: Int, feedID: Int, commentID: Int, content: String) -> Observable<CommentContent> {
FeedsService.shared.updateComment(plubbingID: plubbingID, feedID: feedID, commentID: commentID, comment: content)
}
}
51 changes: 31 additions & 20 deletions PLUB/Sources/Views/Home/Clipboard/BoardDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ final class BoardDetailViewController: BaseViewController {

// MARK: Comment Posting View (댓글 작성 UI)

private let replyView = ReplyView().then {
/// 답글을 달거나 댓글을 수정할 때 보여지는 데코레이터 뷰
private let decoratorView = CommentOptionDecoratorView().then {
$0.backgroundColor = .background
$0.isHidden = true
}
Expand Down Expand Up @@ -68,7 +69,7 @@ final class BoardDetailViewController: BaseViewController {

override func setupLayouts() {
super.setupLayouts()
[collectionView, commentInputView, replyView].forEach {
[collectionView, commentInputView, decoratorView].forEach {
view.addSubview($0)
}
}
Expand All @@ -85,7 +86,7 @@ final class BoardDetailViewController: BaseViewController {
$0.bottom.equalTo(view.safeAreaLayoutGuide)
}

replyView.snp.makeConstraints {
decoratorView.snp.makeConstraints {
$0.directionalHorizontalEdges.equalTo(view.safeAreaLayoutGuide)
$0.bottom.equalTo(commentInputView.snp.top)
$0.height.equalTo(28)
Expand All @@ -101,30 +102,34 @@ final class BoardDetailViewController: BaseViewController {

// == comment posting delegate ==
commentInputView.delegate = self
replyView.delegate = self
decoratorView.delegate = self
}

override func bind() {
super.bind()
collectionView.rx.setDelegate(self).disposed(by: disposeBag)

viewModel.replyNicknameObserable
.subscribe(with: self) { owner, nickname in
owner.replyView.nickname = nickname
owner.replyView.isHidden = false
viewModel.decoratorNameObserable
.subscribe(with: self) { owner, tuple in
owner.decoratorView.labelText = tuple.labelText
owner.decoratorView.buttonText = tuple.buttonText
owner.decoratorView.isHidden = false
}
.disposed(by: disposeBag)

viewModel.showBottomSheetObservable
.subscribe(with: self) { owner, userType in
let bottomSheetVC = CommentOptionBottomSheetViewController(userAccessType: userType).then {
.subscribe(with: self) { owner, tuple in
let bottomSheetVC = CommentOptionBottomSheetViewController(commentID: tuple.commentID, userAccessType: tuple.userType).then {
$0.delegate = owner
}
owner.present(bottomSheetVC, animated: true)

}
.disposed(by: disposeBag)

viewModel.editCommentTextObservable
.bind(to: commentInputView.rx.commentText)
.disposed(by: disposeBag)

// ViewModel에게 `DiffableDataSource`처리를 해주기 위해 collectionView를 전달
viewModel.setCollectionViewObserver.onNext(collectionView)

Expand Down Expand Up @@ -163,30 +168,36 @@ extension BoardDetailViewController: CommentInputViewDelegate {
func commentInputView(_ textView: UITextView, writtenText: String) {
textView.text = ""
viewModel.commentsInput.onNext(writtenText)
decoratorView.isHidden = true
}
}

// MARK: - ReplyViewDelegate
// MARK: - CommentOptionViewDelegate

extension BoardDetailViewController: ReplyViewDelegate {
extension BoardDetailViewController: CommentOptionViewDelegate {
func cancelButtonTapped() {
viewModel.replyIDObserver.onNext(nil)
replyView.isHidden = true
viewModel.commentOptionObserver.onNext(.commentOrReply)
viewModel.targetIDObserver.onNext(nil)
decoratorView.isHidden = true
}
}

// MARK: - CommentOptionBottomSheetDelegate

extension BoardDetailViewController: CommentOptionBottomSheetDelegate {
func deleteButtonTapped() {
viewModel.deleteOptionObserver.onNext(Void())
func deleteButtonTapped(commentID: Int) {
// 순서 중요
viewModel.targetIDObserver.onNext(commentID)
viewModel.commentOptionObserver.onNext(.delete)
}

func editButtonTapped() {
print(#function)
func editButtonTapped(commentID: Int) {
// 순서 중요
viewModel.targetIDObserver.onNext(commentID)
viewModel.commentOptionObserver.onNext(.edit)
}

func reportButtonTapped() {
func reportButtonTapped(commentID: Int) {
print(#function)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ final class ClipboardViewController: BaseViewController {
content: model.toBoardModel,
getCommentsUseCase: DefaultGetCommentsUseCase(),
postCommentUseCase: DefaultPostCommentUseCase(),
deleteCommentUseCase: DefaultDeleteCommentUseCase()
deleteCommentUseCase: DefaultDeleteCommentUseCase(),
editCommentUseCase: DefaultEditCommentUseCase()
)
),
animated: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ final class CommentInputView: UIView {

// MARK: - Properties

/// 댓글 작성란에 들어갈 텍스트를 입력합니다.
var commentText: String {
get {
textView.text
} set {
textView.text = newValue
}
}
Comment on lines +28 to +34
Copy link
Contributor

Choose a reason for hiding this comment

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

아 이런식으로 하면 훨씬 가독성있겠네요👍


private let disposeBag = DisposeBag()

weak var delegate: CommentInputViewDelegate?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import SnapKit
import Then

protocol CommentOptionBottomSheetDelegate: AnyObject {
func deleteButtonTapped()
func editButtonTapped()
func reportButtonTapped()
func deleteButtonTapped(commentID: Int)
func editButtonTapped(commentID: Int)
func reportButtonTapped(commentID: Int)
}


Expand All @@ -35,6 +35,8 @@ final class CommentOptionBottomSheetViewController: BottomSheetViewController {

// MARK: - Properties

private let commentID: Int

private let userAccessType: UserAccessType

weak var delegate: CommentOptionBottomSheetDelegate?
Expand All @@ -53,7 +55,8 @@ final class CommentOptionBottomSheetViewController: BottomSheetViewController {

// MARK: - Initializations

init(userAccessType: UserAccessType) {
init(commentID: Int, userAccessType: UserAccessType) {
self.commentID = commentID
self.userAccessType = userAccessType
super.init(nibName: nil, bundle: nil)
}
Expand Down Expand Up @@ -110,7 +113,14 @@ final class CommentOptionBottomSheetViewController: BottomSheetViewController {

deleteCommentView.button.rx.tap
.subscribe(with: self) { owner, _ in
owner.delegate?.deleteButtonTapped()
owner.delegate?.deleteButtonTapped(commentID: owner.commentID)
owner.dismiss(animated: true)
}
.disposed(by: disposeBag)

editCommentView.button.rx.tap
.subscribe(with: self) { owner, _ in
owner.delegate?.editButtonTapped(commentID: owner.commentID)
owner.dismiss(animated: true)
}
.disposed(by: disposeBag)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// ReplyView.swift
// CommentOptionDecoratorView.swift
// PLUB
//
// Created by 홍승현 on 2023/04/14.
Expand All @@ -12,22 +12,29 @@ import RxCocoa
import SnapKit
import Then

protocol ReplyViewDelegate: AnyObject {
protocol CommentOptionViewDelegate: AnyObject {
func cancelButtonTapped()
}

final class ReplyView: UIView {
final class CommentOptionDecoratorView: UIView {

// MARK: - Properties

/// 답글을 달 닉네임을 설정합니다.
var nickname: String = "Unknown" {
/// 왼쪽에 들어갈 label text를 설정합니다.
var labelText: String = "Unknown" {
didSet {
replyIndicatorLabel.text = "\(nickname)님에게 답글 쓰는 중..."
indicatorLabel.text = labelText
}
}

weak var delegate: ReplyViewDelegate?
/// 오른쪽 버튼에 들어갈 text를 설정합니다.
var buttonText: String = "취소" {
didSet {
cancelButton.setTitle(buttonText, for: .normal)
}
}

weak var delegate: CommentOptionViewDelegate?

private let disposeBag = DisposeBag()

Expand All @@ -37,12 +44,12 @@ final class ReplyView: UIView {
$0.backgroundColor = .lightGray
}

private let replyIndicatorLabel = UILabel().then {
private let indicatorLabel = UILabel().then {
$0.font = .overLine
$0.textColor = .black
}

private let replyCancelButton = UIButton().then {
private let cancelButton = UIButton().then {
$0.setTitleColor(.main, for: .normal)
$0.setTitle("답글 작성 취소", for: .normal)
$0.titleLabel?.font = .overLine
Expand All @@ -64,18 +71,18 @@ final class ReplyView: UIView {
// MARK: - Configuration

private func setupLayouts() {
[replyIndicatorLabel, replyCancelButton, separatorLineView].forEach {
[indicatorLabel, cancelButton, separatorLineView].forEach {
addSubview($0)
}
}

private func setupConstraints() {
replyIndicatorLabel.snp.makeConstraints {
indicatorLabel.snp.makeConstraints {
$0.leading.equalToSuperview().inset(Metrics.directionalHorizontalInset)
$0.centerY.equalToSuperview()
}

replyCancelButton.snp.makeConstraints {
cancelButton.snp.makeConstraints {
$0.centerY.equalToSuperview()
$0.trailing.equalToSuperview().inset(Metrics.directionalHorizontalInset)
}
Expand All @@ -87,15 +94,15 @@ final class ReplyView: UIView {
}

private func bind() {
replyCancelButton.rx.tap
cancelButton.rx.tap
.subscribe(with: self) { owner, _ in
owner.delegate?.cancelButtonTapped()
}
.disposed(by: disposeBag)
}
}

extension ReplyView {
extension CommentOptionDecoratorView {
enum Metrics {
static let directionalHorizontalInset = 24
static let separatorHeight = 1
Expand Down
Loading