Skip to content

Commit 4d5dcfe

Browse files
committed
[#169] 마이페이지 uiState 연결
1 parent 44123db commit 4d5dcfe

File tree

4 files changed

+44
-7
lines changed

4 files changed

+44
-7
lines changed

feature/profile/src/main/kotlin/team/noweekend/feature/profile/mvi/ProfileUiState.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,31 @@ package team.noweekend.feature.profile.mvi
22

33
import androidx.compose.runtime.Stable
44
import team.noweekend.core.common.android.mvi.UiState
5+
import team.noweekend.core.model.user.User
56

67
@Stable
78
data class ProfileUiState(
89
val isLoading: Boolean,
10+
val user: User,
911
) : UiState {
1012
companion object {
1113
val INITIAL_STATE: ProfileUiState = ProfileUiState(
1214
isLoading = false,
15+
user = User(
16+
userId = "",
17+
userEmail = "",
18+
userName = "",
19+
userGender = "",
20+
userBirth = "",
21+
oAuthId = "",
22+
oAuthType = "",
23+
revocableToken = "",
24+
role = "",
25+
remainingAnnualLeave = 0f,
26+
latitude = null,
27+
longitude = null,
28+
averageTemperature = 0f,
29+
),
1330
)
1431
}
1532
}

feature/profile/src/main/kotlin/team/noweekend/feature/profile/mvi/ProfileViewModel.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
package team.noweekend.feature.profile.mvi
22

3+
import android.util.Log
34
import androidx.lifecycle.SavedStateHandle
45
import dagger.hilt.android.lifecycle.HiltViewModel
56
import team.noweekend.core.common.android.base.MVIViewModel
7+
import team.noweekend.core.domain.usecase.GetUserProfileUseCase
68
import team.noweekend.feature.profile.model.Menu
79
import team.noweekend.feature.profile.model.WebLinkMenu
810
import javax.inject.Inject
911

1012
@HiltViewModel
1113
class ProfileViewModel @Inject constructor(
1214
savedStateHandle: SavedStateHandle,
15+
private val getUserProfileUseCase: GetUserProfileUseCase,
1316
) : MVIViewModel<ProfileIntent, ProfileSideEffect, ProfileUiState>(
1417
savedStateHandle = savedStateHandle,
1518
) {
19+
20+
init {
21+
getUserProfile()
22+
}
23+
1624
override fun createInitialState(savedStateHandle: SavedStateHandle): ProfileUiState {
1725
return ProfileUiState.INITIAL_STATE
1826
}
@@ -26,6 +34,16 @@ class ProfileViewModel @Inject constructor(
2634
}
2735
}
2836

37+
private fun getUserProfile() = execute {
38+
getUserProfileUseCase.invoke()
39+
.onSuccess {
40+
reduce { copy(user = it) }
41+
}
42+
.onFailure {
43+
Log.d("logtag", "$it")
44+
}
45+
}
46+
2947
private fun handleMenuTab(menu: Menu) {
3048
when (menu) {
3149
is WebLinkMenu -> navigateToExternalWebBrowser(menu.url)

feature/profile/src/main/kotlin/team/noweekend/feature/profile/screen/ProfileRoute.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ internal fun ProfileRoute(
3131
}
3232

3333
ProfileScreen(
34+
uiState = uiState,
3435
onMenuClick = { viewModel.intent(ProfileIntent.ClickMenu(it)) },
3536
modifier = modifier,
3637
)

feature/profile/src/main/kotlin/team/noweekend/feature/profile/screen/ProfileScreen.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import androidx.compose.foundation.layout.Spacer
66
import androidx.compose.foundation.layout.fillMaxSize
77
import androidx.compose.foundation.layout.height
88
import androidx.compose.runtime.Composable
9+
import androidx.compose.runtime.State
10+
import androidx.compose.runtime.mutableStateOf
11+
import androidx.compose.runtime.remember
912
import androidx.compose.ui.Modifier
1013
import androidx.compose.ui.res.stringResource
1114
import androidx.compose.ui.tooling.preview.Preview
@@ -19,9 +22,11 @@ import team.noweekend.feature.profile.component.topbar.ProfileTopBar
1922
import team.noweekend.feature.profile.model.EtcMenu.Companion.etcMenuList
2023
import team.noweekend.feature.profile.model.InfoMenu.Companion.infoMenuList
2124
import team.noweekend.feature.profile.model.Menu
25+
import team.noweekend.feature.profile.mvi.ProfileUiState
2226

2327
@Composable
2428
internal fun ProfileScreen(
29+
uiState: State<ProfileUiState>,
2530
modifier: Modifier = Modifier,
2631
onMenuClick: (Menu) -> Unit,
2732
) {
@@ -31,11 +36,11 @@ internal fun ProfileScreen(
3136
.background(color = NWKTheme.color.Neutral.white),
3237
) {
3338
ProfileTopBar(
34-
userName = "userName",
39+
userName = uiState.value.user.userName,
3540
onClickEditButton = {},
3641
)
3742
VacationBoard(
38-
lessVacationCount = 12.5f,
43+
lessVacationCount = uiState.value.user.remainingAnnualLeave,
3944
usedVacationCount = 5.5f,
4045
)
4146
MenuLayout(
@@ -46,15 +51,12 @@ internal fun ProfileScreen(
4651
Spacer(
4752
modifier = Modifier.height(16.dp),
4853
)
49-
5054
MenuLayout(
5155
title = stringResource(id = EtcMenuTitle),
5256
menuList = etcMenuList,
5357
onClickMenuItem = onMenuClick,
5458
)
5559
}
56-
57-
5860
}
5961

6062

@@ -65,10 +67,9 @@ private fun PreviewProfileScreen(
6567
) {
6668
NWKTheme {
6769
ProfileScreen(
70+
uiState = remember { mutableStateOf(ProfileUiState.INITIAL_STATE) },
6871
modifier = Modifier.fillMaxSize(),
6972
onMenuClick = {},
7073
)
7174
}
72-
73-
7475
}

0 commit comments

Comments
 (0)