diff --git a/presentation/src/main/java/com/kusitms/presentation/ui/notice/NoticeScreen.kt b/presentation/src/main/java/com/kusitms/presentation/ui/notice/NoticeScreen.kt index 152aef1..6b4e184 100644 --- a/presentation/src/main/java/com/kusitms/presentation/ui/notice/NoticeScreen.kt +++ b/presentation/src/main/java/com/kusitms/presentation/ui/notice/NoticeScreen.kt @@ -95,13 +95,19 @@ fun NoticeScreen( onClickUnreadNoticeFilter = { viewModel.updateVisibleOnlyUnreadNotice(it) }, - onNoticeClick = onNoticeClick + onNoticeClick = { + onNoticeClick(it) + viewModel.updateNoticeAsViewedInList(it.noticeId) + } ) } NoticeTab.CURRICULUM-> { CurriculumListScreen( curriculumList = curriculumList, - onNoticeClick = onNoticeClick + onNoticeClick = { + onNoticeClick(it) + viewModel.updateNoticeAsViewedInList(it.noticeId) + } ) } } diff --git a/presentation/src/main/java/com/kusitms/presentation/ui/notice/NoticeViewModel.kt b/presentation/src/main/java/com/kusitms/presentation/ui/notice/NoticeViewModel.kt index 94d1a60..8c6fa74 100644 --- a/presentation/src/main/java/com/kusitms/presentation/ui/notice/NoticeViewModel.kt +++ b/presentation/src/main/java/com/kusitms/presentation/ui/notice/NoticeViewModel.kt @@ -2,6 +2,7 @@ package com.kusitms.presentation.ui.notice import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.kusitms.domain.model.notice.NoticeModel import com.kusitms.domain.usecase.notice.GetCurriculumListUseCase import com.kusitms.domain.usecase.notice.GetNoticeListUseCase import dagger.hilt.android.lifecycle.HiltViewModel @@ -10,23 +11,30 @@ import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.catch +import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch import javax.inject.Inject @HiltViewModel class NoticeViewModel @Inject constructor( - getNoticeListUseCase: GetNoticeListUseCase, + private val getNoticeListUseCase: GetNoticeListUseCase, getCurriculumListUseCase: GetCurriculumListUseCase ) : ViewModel() { - val noticeList = getNoticeListUseCase().catch { + private val _noticeList = MutableStateFlow>(emptyList()) + val noticeList : StateFlow> = _noticeList.asStateFlow() - }.stateIn( - viewModelScope, - started = SharingStarted.Eagerly, - initialValue = emptyList() - ) + init { + viewModelScope.launch { + getNoticeListUseCase().catch { + + }.collect { + _noticeList.emit(it) + } + } + + } val curriculumList = getCurriculumListUseCase().catch { @@ -44,4 +52,15 @@ class NoticeViewModel @Inject constructor( _visibleOnlyUnreadNotice.emit(isVisible) } } + + fun updateNoticeAsViewedInList(noticeId : Int){ + viewModelScope.launch { + _noticeList.emit( + noticeList.value.map { + if(it.noticeId == noticeId && !it.viewYn) it.copy(viewYn = true) + else it + } + ) + } + } } \ No newline at end of file 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 f2e73d7..158f4b1 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 @@ -68,7 +68,8 @@ fun NoticeCommentBottom( noticeDetailViewModel: NoticeDetailViewModel = hiltViewModel(), targetComment : CommentModel, onClickChildReport : (NoticeDetailModalState.Report) -> Unit, - onClickChildDelete : (NoticeDetailDialogState.CommentDelete) -> Unit + onClickChildDelete : (NoticeDetailDialogState.CommentDelete) -> Unit, + onDismiss: () -> Unit = {} ){ val childCommentList by noticeDetailViewModel.childCommentList.collectAsStateWithLifecycle() @@ -95,7 +96,20 @@ fun NoticeCommentBottom( NoticeComment( comment = targetComment, commentCount = childCommentList.size, - isParentCommentAsReply = true + isParentCommentAsReply = true, + onClickReport = { + onClickChildReport( + NoticeDetailModalState.Report(targetComment, targetComment.writerId) + ) + }, + onClickDelete = { + onClickChildDelete( + NoticeDetailDialogState.CommentDelete( + comment = targetComment + ) + ) + onDismiss() + } ) KusitmsMarginVerticalSpacer(size = 20) 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 cdc8f66..2e92399 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 @@ -282,6 +282,9 @@ fun NoticeDetailScreen( }, onClickChildDelete = { openDialogState = it + }, + onDismiss = { + openBottomSheet = null } ) } 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 39906c0..12f01ac 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 @@ -155,6 +155,7 @@ class NoticeDetailViewModel @Inject constructor( ).catch { _snackbarEvent.emit(NoticeDetailSnackbarEvent.NETWORK_ERROR) }.collectLatest { + fetchCommentList() fetchChildCommentList(commentId) } }