Skip to content

Commit

Permalink
Merge pull request #98 from Mnseo/feature/fix-notice-child-comment-re…
Browse files Browse the repository at this point in the history
…fresh

[FEAT] 공지 대댓글 추가 및 삭제 시 갱신되지 않는 문제 수정
  • Loading branch information
eshc123 authored Feb 1, 2024
2 parents b5963b3 + 97351de commit 9428164
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ fun NoticeCommentBottom(
KusitmsMarginVerticalSpacer(size = 20)
NoticeComment(
comment = targetComment,
commentCount = childCommentList.size,
isParentCommentAsReply = true
)
KusitmsMarginVerticalSpacer(size = 20)
Expand Down Expand Up @@ -125,7 +126,10 @@ fun NoticeCommentBottom(
},
onClickDelete = {
onClickChildDelete(
NoticeDetailDialogState.CommentDelete(comment)
NoticeDetailDialogState.CommentDelete(
comment = comment,
parentComment = targetComment
)
)

},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -142,8 +142,6 @@ fun NoticeDetailScreen(
viewModel.snackbarEvent.collect {
onShowSnackbar(
when(it){
NoticeDetailSnackbarEvent.ADDED_COMMENT -> "댓글이 추가되었습니다."
NoticeDetailSnackbarEvent.DELETED_COMMENT -> "댓글이 삭제되었습니다."
NoticeDetailSnackbarEvent.REPORTED_COMMENT -> "댓글 신고가 완료되었습니다."
NoticeDetailSnackbarEvent.NETWORK_ERROR -> "네트워크 에러가 발생하였습니다."
}
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -372,7 +377,6 @@ fun NoticeDetailScreen(
.weight(1f)
.padding(top = 20.dp)
,
//contentPadding = PaddingValues(top = ),
state = listState
) {
item {
Expand Down Expand Up @@ -449,6 +453,7 @@ fun NoticeDetailScreen(
}
NoticeComment(
comment = comment,
commentCount = comment.commentCount,
onClickReport = {
openBottomSheet =
NoticeDetailModalState.Report(comment, comment.writerId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ class NoticeDetailViewModel @Inject constructor(
_snackbarEvent.emit(NoticeDetailSnackbarEvent.NETWORK_ERROR)
}.collectLatest {
fetchCommentList()
_snackbarEvent.emit(NoticeDetailSnackbarEvent.ADDED_COMMENT)
}
}
}
Expand All @@ -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)
}
}
}
Expand All @@ -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)
}
}
}
Expand Down Expand Up @@ -189,7 +211,6 @@ class NoticeDetailViewModel @Inject constructor(
noticeId
).catch {
_noticeVote.emit(null)
//_snackbarEvent.emit(NoticeDetailSnackbarEvent.NETWORK_ERROR)
}.collectLatest {
_noticeVote.emit(it)
}
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {},
Expand Down Expand Up @@ -157,7 +158,7 @@ fun NoticeComment(
)
KusitmsMarginHorizontalSpacer(size = 4)
Text(
text ="${comment.commentCount}",
text ="${commentCount}",
style = KusitmsTypo.current.Caption1,
color = KusitmsColorPalette.current.GreyBlack7
)
Expand Down

0 comments on commit 9428164

Please sign in to comment.