Skip to content

Commit e7a6b02

Browse files
committed
Refactor: 롤백 에러 다이얼로그 HomeState로 관리
1 parent 4ec0a5b commit e7a6b02

3 files changed

Lines changed: 31 additions & 0 deletions

File tree

presentation/src/main/java/com/threegap/bitnagil/presentation/screen/home/HomeScreen.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import androidx.compose.ui.tooling.preview.Preview
3030
import androidx.compose.ui.unit.dp
3131
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
3232
import com.threegap.bitnagil.designsystem.BitnagilTheme
33+
import com.threegap.bitnagil.designsystem.component.block.BitnagilConfirmDialog
3334
import com.threegap.bitnagil.designsystem.modifier.clickableWithoutRipple
3435
import com.threegap.bitnagil.presentation.screen.home.component.template.CollapsibleHeader
3536
import com.threegap.bitnagil.presentation.screen.home.component.template.EmptyRoutineView
@@ -64,6 +65,15 @@ fun HomeScreenContainer(
6465
}
6566
}
6667

68+
if (uiState.showSyncErrorDialog) {
69+
BitnagilConfirmDialog(
70+
title = "루틴 완료를 저장하지 못했어요",
71+
description = "네트워크 연결에 문제가 있었던 것 같아요.\n다시 한 번 시도해 주세요.",
72+
confirmButtonText = "확인",
73+
onConfirm = viewModel::dismissSyncErrorDialog,
74+
)
75+
}
76+
6777
HomeScreen(
6878
uiState = uiState,
6979
onDateSelect = viewModel::selectDate,

presentation/src/main/java/com/threegap/bitnagil/presentation/screen/home/HomeViewModel.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import androidx.lifecycle.ViewModel
55
import com.threegap.bitnagil.domain.emotion.usecase.ObserveDailyEmotionUseCase
66
import com.threegap.bitnagil.domain.routine.model.ToggleStrategy
77
import com.threegap.bitnagil.domain.routine.usecase.ApplyRoutineToggleUseCase
8+
import com.threegap.bitnagil.domain.routine.usecase.ObserveRoutineSyncErrorUseCase
89
import com.threegap.bitnagil.domain.routine.usecase.ObserveWeeklyRoutinesUseCase
910
import com.threegap.bitnagil.domain.user.usecase.ObserveUserProfileUseCase
1011
import com.threegap.bitnagil.presentation.screen.home.contract.HomeSideEffect
@@ -31,6 +32,7 @@ class HomeViewModel @Inject constructor(
3132
private val observeUserProfileUseCase: ObserveUserProfileUseCase,
3233
private val observeDailyEmotionUseCase: ObserveDailyEmotionUseCase,
3334
private val applyRoutineToggleUseCase: ApplyRoutineToggleUseCase,
35+
private val observeRoutineSyncErrorUseCase: ObserveRoutineSyncErrorUseCase,
3436
) : ContainerHost<HomeState, HomeSideEffect>, ViewModel() {
3537

3638
override val container: Container<HomeState, HomeSideEffect> =
@@ -41,6 +43,7 @@ class HomeViewModel @Inject constructor(
4143
observeDailyEmotion()
4244
observeUserProfile()
4345
observeWeeklyRoutines()
46+
observeRoutineSyncError()
4447
},
4548
)
4649

@@ -87,6 +90,22 @@ class HomeViewModel @Inject constructor(
8790
}
8891
}
8992

93+
private fun observeRoutineSyncError() {
94+
intent {
95+
repeatOnSubscription {
96+
observeRoutineSyncErrorUseCase().collect {
97+
reduce { state.copy(showSyncErrorDialog = true) }
98+
}
99+
}
100+
}
101+
}
102+
103+
fun dismissSyncErrorDialog() {
104+
intent {
105+
reduce { state.copy(showSyncErrorDialog = false) }
106+
}
107+
}
108+
90109
fun selectDate(date: LocalDate) {
91110
intent {
92111
reduce { state.copy(selectedDate = date) }

presentation/src/main/java/com/threegap/bitnagil/presentation/screen/home/contract/HomeState.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ data class HomeState(
1212
val selectedDate: LocalDate,
1313
val currentWeeks: List<LocalDate>,
1414
val routineSchedule: RoutineScheduleUiModel,
15+
val showSyncErrorDialog: Boolean,
1516
) {
1617
val selectedDateRoutines: List<RoutineUiModel>
1718
get() = routineSchedule.dailyRoutines[selectedDate.toString()]?.routines ?: emptyList()
@@ -23,6 +24,7 @@ data class HomeState(
2324
selectedDate = LocalDate.now(),
2425
currentWeeks = LocalDate.now().getCurrentWeekDays(),
2526
routineSchedule = RoutineScheduleUiModel.INIT,
27+
showSyncErrorDialog = false,
2628
)
2729
}
2830
}

0 commit comments

Comments
 (0)