Skip to content

Commit

Permalink
feat : MyPage에서 싱글 기록 조회 수행 #PAR-381
Browse files Browse the repository at this point in the history
  • Loading branch information
nohjunh committed Oct 11, 2023
1 parent 1a48b35 commit 268a522
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ fun MyPageScreen(
myPageViewModel: MyPageViewModel = hiltViewModel(),
navigateToSettings: () -> Unit = {},
navigateToProfile: () -> Unit = {},
navigateToSingleResult: () -> Unit = {},
onShowSnackbar: (String) -> Unit
) {
val myPageProfileState by myPageViewModel.myPageProfileState.collectAsStateWithLifecycle()
Expand All @@ -66,6 +67,7 @@ fun MyPageScreen(
myPageProfileState = myPageProfileState,
navigateToSettings = navigateToSettings,
navigateToProfile = navigateToProfile,
navigateToSingleResult = navigateToSingleResult,
onShowSnackbar = onShowSnackbar,
myPageSnackbarMessage = myPageSnackbarMessage
)
Expand All @@ -79,6 +81,7 @@ fun Content(
myPageProfileState: MyPageProfileState,
navigateToSettings: () -> Unit,
navigateToProfile: () -> Unit,
navigateToSingleResult: () -> Unit,
onShowSnackbar: (String) -> Unit,
myPageSnackbarMessage: String
) {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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))
Expand All @@ -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)
Expand All @@ -233,7 +250,8 @@ private fun SingleRunningHistoryRow(

@Composable
private fun SingleRunningHistoryBody(
singleRunningHistory: SingleRunningHistory
singleRunningHistory: SingleRunningHistory,
myPageViewModel: MyPageViewModel
) {
Column(
modifier = Modifier
Expand All @@ -256,9 +274,10 @@ private fun SingleRunningHistoryBody(
items(singleRunningHistory.history) { data ->
RunningDataCard(
runningHistoryDetail = data,
isSingleData = true,
onClick = { }
)
isSingleData = true
) {
myPageViewModel.saveSingleId(data.id)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -13,16 +13,17 @@ 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

@HiltViewModel
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>(MyPageProfileState.Loading)
val myPageProfileState = _myPageProfileState.asStateFlow()
Expand All @@ -35,6 +36,8 @@ class MyPageViewModel @Inject constructor(
MutableStateFlow<RunningHistoryState>(RunningHistoryState.Loading)
val runningHistoryState = _runningHistoryState.asStateFlow()

val saveIdCompleteEvent = MutableSharedFlow<ModeType>(replay = 0)

private val _snackbarMessage = MutableStateFlow("")
val snackbarMessage: StateFlow<String> = _snackbarMessage

Expand Down Expand Up @@ -90,6 +93,11 @@ class MyPageViewModel @Inject constructor(
}
}

fun saveSingleId(singleId: String) = viewModelScope.launch {
saveSingleIdUseCase(singleId)
saveIdCompleteEvent.emit(ModeType.SINGLE)
}

fun clearSnackbarMessage() {
_snackbarMessage.value = ""
}
Expand Down

0 comments on commit 268a522

Please sign in to comment.