Skip to content

Commit 659b2e5

Browse files
committed
Refactor: MyPageViewModel 에서 MviViewModel 구현 제거 및 orbit ContainerHost 직접 사용
1 parent a697338 commit 659b2e5

5 files changed

Lines changed: 23 additions & 56 deletions

File tree

presentation/src/main/java/com/threegap/bitnagil/presentation/mypage/MyPageScreen.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import androidx.compose.foundation.shape.CircleShape
1414
import androidx.compose.material3.HorizontalDivider
1515
import androidx.compose.material3.Text
1616
import androidx.compose.runtime.Composable
17-
import androidx.compose.runtime.collectAsState
1817
import androidx.compose.runtime.getValue
1918
import androidx.compose.ui.Alignment
2019
import androidx.compose.ui.Modifier
@@ -30,6 +29,7 @@ import com.threegap.bitnagil.designsystem.component.atom.BitnagilIconButton
3029
import com.threegap.bitnagil.designsystem.component.block.BitnagilOptionButton
3130
import com.threegap.bitnagil.designsystem.component.block.BitnagilTopBar
3231
import com.threegap.bitnagil.presentation.mypage.model.MyPageState
32+
import org.orbitmvi.orbit.compose.collectAsState
3333

3434
@Composable
3535
fun MyPageScreenContainer(
@@ -39,7 +39,7 @@ fun MyPageScreenContainer(
3939
navigateToQnA: () -> Unit,
4040
navigateToOnBoarding: () -> Unit,
4141
) {
42-
val state by myPageViewModel.stateFlow.collectAsState()
42+
val state by myPageViewModel.collectAsState()
4343

4444
MyPageScreen(
4545
state = state,
Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,37 @@
11
package com.threegap.bitnagil.presentation.mypage
22

3-
import androidx.lifecycle.SavedStateHandle
4-
import androidx.lifecycle.viewModelScope
3+
import androidx.lifecycle.ViewModel
54
import com.threegap.bitnagil.domain.user.usecase.FetchUserProfileUseCase
6-
import com.threegap.bitnagil.presentation.common.mviviewmodel.MviViewModel
7-
import com.threegap.bitnagil.presentation.mypage.model.MyPageIntent
85
import com.threegap.bitnagil.presentation.mypage.model.MyPageSideEffect
96
import com.threegap.bitnagil.presentation.mypage.model.MyPageState
107
import dagger.hilt.android.lifecycle.HiltViewModel
11-
import kotlinx.coroutines.launch
12-
import org.orbitmvi.orbit.syntax.Syntax
8+
import org.orbitmvi.orbit.Container
9+
import org.orbitmvi.orbit.ContainerHost
10+
import org.orbitmvi.orbit.viewmodel.container
1311
import javax.inject.Inject
1412

1513
@HiltViewModel
1614
class MyPageViewModel @Inject constructor(
17-
savedStateHandle: SavedStateHandle,
1815
private val fetchUserProfileUseCase: FetchUserProfileUseCase,
19-
) : MviViewModel<MyPageState, MyPageSideEffect, MyPageIntent>(
20-
MyPageState.Init,
21-
savedStateHandle,
22-
) {
16+
) : ContainerHost<MyPageState, MyPageSideEffect>, ViewModel() {
17+
override val container: Container<MyPageState, MyPageSideEffect> = container(initialState = MyPageState.Init)
18+
2319
init {
2420
loadMyPageInfo()
2521
}
2622

27-
private fun loadMyPageInfo() {
28-
viewModelScope.launch {
29-
fetchUserProfileUseCase().fold(
30-
onSuccess = {
31-
sendIntent(
32-
MyPageIntent.LoadMyPageSuccess(
33-
name = it.nickname,
34-
profileUrl = "profileUrl",
35-
),
23+
private fun loadMyPageInfo() = intent {
24+
fetchUserProfileUseCase().fold(
25+
onSuccess = {
26+
reduce {
27+
state.copy(
28+
name = it.nickname,
29+
profileUrl = "profileUrl",
3630
)
37-
},
38-
onFailure = {
39-
},
40-
)
41-
}
42-
}
43-
44-
override suspend fun Syntax<MyPageState, MyPageSideEffect>.reduceState(
45-
intent: MyPageIntent,
46-
state: MyPageState,
47-
): MyPageState {
48-
when (intent) {
49-
is MyPageIntent.LoadMyPageSuccess -> {
50-
return state.copy(
51-
name = intent.name,
52-
profileUrl = intent.profileUrl,
53-
)
54-
}
55-
}
31+
}
32+
},
33+
onFailure = {
34+
},
35+
)
5636
}
5737
}

presentation/src/main/java/com/threegap/bitnagil/presentation/mypage/model/MyPageIntent.kt

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
package com.threegap.bitnagil.presentation.mypage.model
22

3-
import com.threegap.bitnagil.presentation.common.mviviewmodel.MviSideEffect
4-
5-
sealed class MyPageSideEffect : MviSideEffect
3+
sealed class MyPageSideEffect

presentation/src/main/java/com/threegap/bitnagil/presentation/mypage/model/MyPageState.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
package com.threegap.bitnagil.presentation.mypage.model
22

3-
import com.threegap.bitnagil.presentation.common.mviviewmodel.MviState
4-
import kotlinx.parcelize.Parcelize
5-
6-
@Parcelize
73
data class MyPageState(
84
val name: String,
95
val profileUrl: String,
10-
) : MviState {
6+
) {
117
companion object {
128
val Init = MyPageState(name = "", profileUrl = "")
139
}

0 commit comments

Comments
 (0)