From 97351de4e90ec611745d26afe5a8fc5bcb982576 Mon Sep 17 00:00:00 2001 From: Jung SeokJoon Date: Wed, 31 Jan 2024 22:58:21 +0900 Subject: [PATCH] =?UTF-8?q?fix=20=EA=B3=B5=EC=A7=80=20=EB=8C=80=EB=8C=93?= =?UTF-8?q?=EA=B8=80=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=20=EA=B0=B1=EC=8B=A0=EB=90=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20?= =?UTF-8?q?=EB=AC=B8=EC=A0=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notice/detail/NoticeDetailBottomSheet.kt | 6 +++- .../ui/notice/detail/NoticeDetailScreen.kt | 19 ++++++---- .../ui/notice/detail/NoticeDetailViewModel.kt | 35 +++++++++++++++---- .../ui/notice/detail/comment/NoticeComment.kt | 3 +- 4 files changed, 47 insertions(+), 16 deletions(-) diff --git a/presentation/src/main/java/com/kusitms/presentation/ui/notice/detail/NoticeDetailBottomSheet.kt b/presentation/src/main/java/com/kusitms/presentation/ui/notice/detail/NoticeDetailBottomSheet.kt index cf76c4cf..f2e73d72 100644 --- a/presentation/src/main/java/com/kusitms/presentation/ui/notice/detail/NoticeDetailBottomSheet.kt +++ b/presentation/src/main/java/com/kusitms/presentation/ui/notice/detail/NoticeDetailBottomSheet.kt @@ -94,6 +94,7 @@ fun NoticeCommentBottom( KusitmsMarginVerticalSpacer(size = 20) NoticeComment( comment = targetComment, + commentCount = childCommentList.size, isParentCommentAsReply = true ) KusitmsMarginVerticalSpacer(size = 20) @@ -125,7 +126,10 @@ fun NoticeCommentBottom( }, onClickDelete = { onClickChildDelete( - NoticeDetailDialogState.CommentDelete(comment) + NoticeDetailDialogState.CommentDelete( + comment = comment, + parentComment = targetComment + ) ) }, diff --git a/presentation/src/main/java/com/kusitms/presentation/ui/notice/detail/NoticeDetailScreen.kt b/presentation/src/main/java/com/kusitms/presentation/ui/notice/detail/NoticeDetailScreen.kt index 07a87cb1..cdc8f66f 100644 --- a/presentation/src/main/java/com/kusitms/presentation/ui/notice/detail/NoticeDetailScreen.kt +++ b/presentation/src/main/java/com/kusitms/presentation/ui/notice/detail/NoticeDetailScreen.kt @@ -73,7 +73,7 @@ sealed class NoticeDetailDialogState() { object AlreadyReport : NoticeDetailDialogState() - data class CommentDelete(val comment: CommentModel,val isChild : Boolean = false) : NoticeDetailDialogState() + data class CommentDelete(val comment: CommentModel,val parentComment : CommentModel? = null) : NoticeDetailDialogState() } sealed class NoticeDetailModalState() { @@ -142,8 +142,6 @@ fun NoticeDetailScreen( viewModel.snackbarEvent.collect { onShowSnackbar( when(it){ - NoticeDetailSnackbarEvent.ADDED_COMMENT -> "댓글이 추가되었습니다." - NoticeDetailSnackbarEvent.DELETED_COMMENT -> "댓글이 삭제되었습니다." NoticeDetailSnackbarEvent.REPORTED_COMMENT -> "댓글 신고가 완료되었습니다." NoticeDetailSnackbarEvent.NETWORK_ERROR -> "네트워크 에러가 발생하였습니다." } @@ -218,9 +216,16 @@ fun NoticeDetailScreen( okColor = KusitmsColorPalette.current.Grey200, okText = "삭제하기", onOk = { - viewModel.deleteNoticeComment( - commentDeleteState.comment.commentId - ) + if(commentDeleteState.parentComment != null){ + viewModel.deleteNoticeChildComment( + commentDeleteState.comment.commentId, + commentDeleteState.parentComment.commentId + ) + }else { + viewModel.deleteNoticeComment( + commentDeleteState.comment.commentId, + ) + } openDialogState = null }, onCancel = { @@ -372,7 +377,6 @@ fun NoticeDetailScreen( .weight(1f) .padding(top = 20.dp) , - //contentPadding = PaddingValues(top = ), state = listState ) { item { @@ -449,6 +453,7 @@ fun NoticeDetailScreen( } NoticeComment( comment = comment, + commentCount = comment.commentCount, onClickReport = { openBottomSheet = NoticeDetailModalState.Report(comment, comment.writerId) diff --git a/presentation/src/main/java/com/kusitms/presentation/ui/notice/detail/NoticeDetailViewModel.kt b/presentation/src/main/java/com/kusitms/presentation/ui/notice/detail/NoticeDetailViewModel.kt index dfe43018..39906c0a 100644 --- a/presentation/src/main/java/com/kusitms/presentation/ui/notice/detail/NoticeDetailViewModel.kt +++ b/presentation/src/main/java/com/kusitms/presentation/ui/notice/detail/NoticeDetailViewModel.kt @@ -120,7 +120,6 @@ class NoticeDetailViewModel @Inject constructor( _snackbarEvent.emit(NoticeDetailSnackbarEvent.NETWORK_ERROR) }.collectLatest { fetchCommentList() - _snackbarEvent.emit(NoticeDetailSnackbarEvent.ADDED_COMMENT) } } } @@ -137,8 +136,12 @@ class NoticeDetailViewModel @Inject constructor( ).catch { _snackbarEvent.emit(NoticeDetailSnackbarEvent.NETWORK_ERROR) }.collectLatest { - fetchCommentList() - _snackbarEvent.emit(NoticeDetailSnackbarEvent.ADDED_COMMENT) + _commentList.emit(commentList.value.map { + it.copy( + commentCount = it.commentCount + 1 + ) + }) + fetchChildCommentList(commentId) } } } @@ -152,8 +155,27 @@ class NoticeDetailViewModel @Inject constructor( ).catch { _snackbarEvent.emit(NoticeDetailSnackbarEvent.NETWORK_ERROR) }.collectLatest { - fetchCommentList() - _snackbarEvent.emit(NoticeDetailSnackbarEvent.DELETED_COMMENT) + fetchChildCommentList(commentId) + } + } + } + + fun deleteNoticeChildComment( + commentId : Int, + parentCommentId : Int + ){ + viewModelScope.launch { + deleteCommentUseCase( + commentId = commentId + ).catch { + _snackbarEvent.emit(NoticeDetailSnackbarEvent.NETWORK_ERROR) + }.collectLatest { + _commentList.emit(commentList.value.map { + it.copy( + commentCount = it.commentCount - 1 + ) + }) + fetchChildCommentList(parentCommentId) } } } @@ -189,7 +211,6 @@ class NoticeDetailViewModel @Inject constructor( noticeId ).catch { _noticeVote.emit(null) - //_snackbarEvent.emit(NoticeDetailSnackbarEvent.NETWORK_ERROR) }.collectLatest { _noticeVote.emit(it) } @@ -218,7 +239,7 @@ class NoticeDetailViewModel @Inject constructor( private const val NOTICE_ID_SAVED_STATE_KEY = "noticeId" enum class NoticeDetailSnackbarEvent { - ADDED_COMMENT, DELETED_COMMENT, REPORTED_COMMENT, NETWORK_ERROR + REPORTED_COMMENT, NETWORK_ERROR } enum class NoticeDetailDialogEvent { diff --git a/presentation/src/main/java/com/kusitms/presentation/ui/notice/detail/comment/NoticeComment.kt b/presentation/src/main/java/com/kusitms/presentation/ui/notice/detail/comment/NoticeComment.kt index 3ced7830..574fee24 100644 --- a/presentation/src/main/java/com/kusitms/presentation/ui/notice/detail/comment/NoticeComment.kt +++ b/presentation/src/main/java/com/kusitms/presentation/ui/notice/detail/comment/NoticeComment.kt @@ -52,6 +52,7 @@ import com.kusitms.presentation.ui.ImageVector.icons.kusitmsicons.UserBackground @Composable fun NoticeComment( comment: CommentModel, + commentCount : Int = 0, isLast : Boolean = false, onClickReport : () -> Unit = {}, onClickDelete : () -> Unit = {}, @@ -157,7 +158,7 @@ fun NoticeComment( ) KusitmsMarginHorizontalSpacer(size = 4) Text( - text ="${comment.commentCount}", + text ="${commentCount}", style = KusitmsTypo.current.Caption1, color = KusitmsColorPalette.current.GreyBlack7 )