@@ -11,7 +11,7 @@ import com.threegap.bitnagil.domain.routine.usecase.FetchWeeklyRoutinesUseCase
1111import com.threegap.bitnagil.domain.routine.usecase.GetWriteRoutineEventFlowUseCase
1212import com.threegap.bitnagil.domain.routine.usecase.RoutineCompletionUseCase
1313import com.threegap.bitnagil.domain.routine.usecase.ToggleRoutineUseCase
14- import com.threegap.bitnagil.domain.user.usecase.FetchUserProfileUseCase
14+ import com.threegap.bitnagil.domain.user.usecase.ObserveUserProfileUseCase
1515import com.threegap.bitnagil.presentation.screen.home.contract.HomeSideEffect
1616import com.threegap.bitnagil.presentation.screen.home.contract.HomeState
1717import com.threegap.bitnagil.presentation.screen.home.model.ToggleStrategy
@@ -35,7 +35,7 @@ import javax.inject.Inject
3535@HiltViewModel
3636class HomeViewModel @Inject constructor(
3737 private val fetchWeeklyRoutinesUseCase : FetchWeeklyRoutinesUseCase ,
38- private val fetchUserProfileUseCase : FetchUserProfileUseCase ,
38+ private val observeUserProfileUseCase : ObserveUserProfileUseCase ,
3939 private val fetchDailyEmotionUseCase : FetchDailyEmotionUseCase ,
4040 private val routineCompletionUseCase : RoutineCompletionUseCase ,
4141 private val getWriteRoutineEventFlowUseCase : GetWriteRoutineEventFlowUseCase ,
@@ -185,7 +185,7 @@ class HomeViewModel @Inject constructor(
185185 private fun initialize () {
186186 intent {
187187 coroutineScope {
188- launch { fetchUserProfile () }
188+ launch { observeUserProfile () }
189189 launch { fetchDailyEmotion() }
190190 launch { fetchWeeklyRoutines(state.currentWeeks) }
191191 launch { observeWriteRoutineEvent() }
@@ -246,18 +246,22 @@ class HomeViewModel @Inject constructor(
246246 }
247247 }
248248
249- private suspend fun fetchUserProfile () {
250- subIntent {
251- reduce { state.copy(loadingCount = state.loadingCount + 1 ) }
252- fetchUserProfileUseCase().fold(
253- onSuccess = {
254- reduce { state.copy(userNickname = it.nickname, loadingCount = state.loadingCount - 1 ) }
255- },
256- onFailure = {
257- Log .e(" HomeViewModel" , " 유저 정보 가져오기 실패: ${it.message} " )
258- reduce { state.copy(loadingCount = state.loadingCount - 1 ) }
259- },
260- )
249+ private fun observeUserProfile () {
250+ intent {
251+ repeatOnSubscription {
252+ reduce { state.copy(loadingCount = state.loadingCount + 1 ) }
253+ observeUserProfileUseCase().collect { result ->
254+ result.fold(
255+ onSuccess = {
256+ reduce { state.copy(userNickname = it.nickname, loadingCount = state.loadingCount - 1 ) }
257+ },
258+ onFailure = {
259+ Log .e(" HomeViewModel" , " 유저 정보 가져오기 실패: ${it.message} " )
260+ reduce { state.copy(loadingCount = state.loadingCount - 1 ) }
261+ },
262+ )
263+ }
264+ }
261265 }
262266 }
263267
0 commit comments