From 268a522e7ad1fe2cded0f3ab2b770cdff5393534 Mon Sep 17 00:00:00 2001 From: Junhyeok Date: Wed, 11 Oct 2023 12:34:46 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20MyPage=EC=97=90=EC=84=9C=20=EC=8B=B1?= =?UTF-8?q?=EA=B8=80=20=EA=B8=B0=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20=EC=88=98?= =?UTF-8?q?=ED=96=89=20#PAR-381?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../feature/my_page/MyPageScreen.kt | 37 ++++++++++++++----- .../feature/my_page/MyPageViewModel.kt | 14 +++++-- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/feature/my_page/src/main/java/online/partyrun/partyrunapplication/feature/my_page/MyPageScreen.kt b/feature/my_page/src/main/java/online/partyrun/partyrunapplication/feature/my_page/MyPageScreen.kt index 807809dc..726980c2 100644 --- a/feature/my_page/src/main/java/online/partyrun/partyrunapplication/feature/my_page/MyPageScreen.kt +++ b/feature/my_page/src/main/java/online/partyrun/partyrunapplication/feature/my_page/MyPageScreen.kt @@ -56,6 +56,7 @@ fun MyPageScreen( myPageViewModel: MyPageViewModel = hiltViewModel(), navigateToSettings: () -> Unit = {}, navigateToProfile: () -> Unit = {}, + navigateToSingleResult: () -> Unit = {}, onShowSnackbar: (String) -> Unit ) { val myPageProfileState by myPageViewModel.myPageProfileState.collectAsStateWithLifecycle() @@ -66,6 +67,7 @@ fun MyPageScreen( myPageProfileState = myPageProfileState, navigateToSettings = navigateToSettings, navigateToProfile = navigateToProfile, + navigateToSingleResult = navigateToSingleResult, onShowSnackbar = onShowSnackbar, myPageSnackbarMessage = myPageSnackbarMessage ) @@ -79,6 +81,7 @@ fun Content( myPageProfileState: MyPageProfileState, navigateToSettings: () -> Unit, navigateToProfile: () -> Unit, + navigateToSingleResult: () -> Unit, onShowSnackbar: (String) -> Unit, myPageSnackbarMessage: String ) { @@ -108,7 +111,8 @@ fun Content( is MyPageProfileState.Success -> MyPageBody( userData = myPageProfileState.user, myPageViewModel = myPageViewModel, - navigateToProfile = navigateToProfile + navigateToProfile = navigateToProfile, + navigateToSingleResult = navigateToSingleResult ) is MyPageProfileState.LoadFailed -> LoadingBody() @@ -156,13 +160,23 @@ private fun LoadingBody() { private fun MyPageBody( userData: User, myPageViewModel: MyPageViewModel, - navigateToProfile: () -> Unit + navigateToProfile: () -> Unit, + navigateToSingleResult: () -> Unit ) { LaunchedEffect(Unit) { myPageViewModel.getComprehensiveRunRecord() myPageViewModel.getSingleRunningHistory() } + LaunchedEffect(Unit) {// 러닝 기록 상세 보기 클릭 + myPageViewModel.saveIdCompleteEvent.collect { modeType -> + when (modeType) { + ModeType.SINGLE -> navigateToSingleResult() + else -> {} + } + } + } + val myPageComprehensiveRunRecordState by myPageViewModel.myPageComprehensiveRunRecordState.collectAsStateWithLifecycle() val runningHistoryState by myPageViewModel.runningHistoryState.collectAsStateWithLifecycle() @@ -193,7 +207,8 @@ private fun MyPageBody( Spacer(modifier = Modifier.height(30.dp)) SingleRunningHistoryRow( - runningHistoryState = runningHistoryState + runningHistoryState = runningHistoryState, + myPageViewModel = myPageViewModel ) Spacer(modifier = Modifier.height(30.dp)) @@ -219,12 +234,14 @@ private fun MyPageBody( @Composable private fun SingleRunningHistoryRow( - runningHistoryState: RunningHistoryState + runningHistoryState: RunningHistoryState, + myPageViewModel: MyPageViewModel ) { when (runningHistoryState) { is RunningHistoryState.Loading -> ShimmerRunningHistory(isSingleData = true) is RunningHistoryState.Success -> SingleRunningHistoryBody( - singleRunningHistory = runningHistoryState.singleRunningHistory + singleRunningHistory = runningHistoryState.singleRunningHistory, + myPageViewModel = myPageViewModel ) RunningHistoryState.LoadFailed -> ShimmerRunningHistory(isSingleData = true) @@ -233,7 +250,8 @@ private fun SingleRunningHistoryRow( @Composable private fun SingleRunningHistoryBody( - singleRunningHistory: SingleRunningHistory + singleRunningHistory: SingleRunningHistory, + myPageViewModel: MyPageViewModel ) { Column( modifier = Modifier @@ -256,9 +274,10 @@ private fun SingleRunningHistoryBody( items(singleRunningHistory.history) { data -> RunningDataCard( runningHistoryDetail = data, - isSingleData = true, - onClick = { } - ) + isSingleData = true + ) { + myPageViewModel.saveSingleId(data.id) + } } } } diff --git a/feature/my_page/src/main/java/online/partyrun/partyrunapplication/feature/my_page/MyPageViewModel.kt b/feature/my_page/src/main/java/online/partyrun/partyrunapplication/feature/my_page/MyPageViewModel.kt index 1fb59b53..7f12737b 100644 --- a/feature/my_page/src/main/java/online/partyrun/partyrunapplication/feature/my_page/MyPageViewModel.kt +++ b/feature/my_page/src/main/java/online/partyrun/partyrunapplication/feature/my_page/MyPageViewModel.kt @@ -3,7 +3,7 @@ package online.partyrun.partyrunapplication.feature.my_page import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel -import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow @@ -13,6 +13,7 @@ import online.partyrun.partyrunapplication.core.common.result.onSuccess import online.partyrun.partyrunapplication.core.domain.my_page.GetComprehensiveRunRecordUseCase import online.partyrun.partyrunapplication.core.domain.my_page.GetMyPageDataUseCase import online.partyrun.partyrunapplication.core.domain.my_page.GetSingleHistoryUseCase +import online.partyrun.partyrunapplication.core.domain.running.single.SaveSingleIdUseCase import timber.log.Timber import javax.inject.Inject @@ -20,9 +21,9 @@ import javax.inject.Inject class MyPageViewModel @Inject constructor( private val getMyPageDataUseCase: GetMyPageDataUseCase, private val getComprehensiveRunRecordUseCase: GetComprehensiveRunRecordUseCase, - private val getSingleHistoryUseCase: GetSingleHistoryUseCase + private val getSingleHistoryUseCase: GetSingleHistoryUseCase, + private val saveSingleIdUseCase: SaveSingleIdUseCase ) : ViewModel() { - private val _myPageProfileState = MutableStateFlow(MyPageProfileState.Loading) val myPageProfileState = _myPageProfileState.asStateFlow() @@ -35,6 +36,8 @@ class MyPageViewModel @Inject constructor( MutableStateFlow(RunningHistoryState.Loading) val runningHistoryState = _runningHistoryState.asStateFlow() + val saveIdCompleteEvent = MutableSharedFlow(replay = 0) + private val _snackbarMessage = MutableStateFlow("") val snackbarMessage: StateFlow = _snackbarMessage @@ -90,6 +93,11 @@ class MyPageViewModel @Inject constructor( } } + fun saveSingleId(singleId: String) = viewModelScope.launch { + saveSingleIdUseCase(singleId) + saveIdCompleteEvent.emit(ModeType.SINGLE) + } + fun clearSnackbarMessage() { _snackbarMessage.value = "" }