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

[FIX] 공지 누락된 기능 수정 #107

Merged
merged 3 commits into from
Feb 9, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<List<NoticeModel>>(emptyList())
val noticeList : StateFlow<List<NoticeModel>> = _noticeList.asStateFlow()

}.stateIn(
viewModelScope,
started = SharingStarted.Eagerly,
initialValue = emptyList()
)
init {
viewModelScope.launch {
getNoticeListUseCase().catch {

}.collect {
_noticeList.emit(it)
}
}

}

val curriculumList = getCurriculumListUseCase().catch {

Expand All @@ -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
}
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ fun NoticeDetailScreen(
},
onClickChildDelete = {
openDialogState = it
},
onDismiss = {
openBottomSheet = null
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ class NoticeDetailViewModel @Inject constructor(
).catch {
_snackbarEvent.emit(NoticeDetailSnackbarEvent.NETWORK_ERROR)
}.collectLatest {
fetchCommentList()
fetchChildCommentList(commentId)
}
}
Expand Down