Skip to content

Commit d4e567b

Browse files
committed
Refactor: 루틴 수정, 삭제 로직 제거
- 루틴 상세 바텀시트 컴포넌트 제거 - 루틴 삭제 모달 컴포넌트 제가 - 수정, 삭제 관련 state, intent 제거
1 parent 987e909 commit d4e567b

10 files changed

Lines changed: 4 additions & 798 deletions

File tree

app/src/main/java/com/threegap/bitnagil/MainNavHost.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,6 @@ fun MainNavHost(
121121
navigateToRegisterRoutine = { routineId ->
122122
navigator.navController.navigate(Route.WriteRoutine(routineId = routineId))
123123
},
124-
navigateToEditRoutine = { routineId ->
125-
navigator.navController.navigate(Route.WriteRoutine(routineId = routineId, isRegister = false))
126-
},
127124
navigateToEmotion = {
128125
navigator.navController.navigate(Route.Emotion)
129126
},

app/src/main/java/com/threegap/bitnagil/navigation/home/HomeNavHost.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ fun HomeNavHost(
4040
navigateToNotice: () -> Unit,
4141
navigateToQnA: () -> Unit,
4242
navigateToRegisterRoutine: (String?) -> Unit,
43-
navigateToEditRoutine: (String) -> Unit,
4443
navigateToEmotion: () -> Unit,
4544
) {
4645
val navigator = rememberHomeNavigator()
@@ -66,7 +65,6 @@ fun HomeNavHost(
6665
navigateToRegisterRoutine = {
6766
navigateToRegisterRoutine(null)
6867
},
69-
navigateToEditRoutine = navigateToEditRoutine,
7068
navigateToEmotion = navigateToEmotion,
7169
)
7270
}

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

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ import com.threegap.bitnagil.designsystem.modifier.clickableWithoutRipple
2727
import com.threegap.bitnagil.presentation.common.flow.collectAsEffect
2828
import com.threegap.bitnagil.presentation.common.toast.GlobalBitnagilToast
2929
import com.threegap.bitnagil.presentation.home.component.template.CollapsibleHomeHeader
30-
import com.threegap.bitnagil.presentation.home.component.template.DeleteConfirmDialog
3130
import com.threegap.bitnagil.presentation.home.component.template.EmptyRoutineView
32-
import com.threegap.bitnagil.presentation.home.component.template.RoutineDetailsBottomSheet
3331
import com.threegap.bitnagil.presentation.home.component.template.RoutineSection
3432
import com.threegap.bitnagil.presentation.home.component.template.WeeklyDatePicker
3533
import com.threegap.bitnagil.presentation.home.model.HomeIntent
@@ -42,7 +40,6 @@ import java.time.LocalDate
4240
fun HomeScreenContainer(
4341
viewModel: HomeViewModel = hiltViewModel(),
4442
navigateToRegisterRoutine: () -> Unit,
45-
navigateToEditRoutine: (String) -> Unit,
4643
navigateToEmotion: () -> Unit,
4744
) {
4845
val uiState by viewModel.stateFlow.collectAsStateWithLifecycle()
@@ -57,10 +54,6 @@ fun HomeScreenContainer(
5754
navigateToEmotion()
5855
}
5956

60-
is HomeSideEffect.NavigateToEditRoutine -> {
61-
navigateToEditRoutine(sideEffect.routineId)
62-
}
63-
6457
is HomeSideEffect.ShowToastWithIcon -> {
6558
GlobalBitnagilToast.showCheck(sideEffect.message)
6659
}
@@ -71,40 +64,6 @@ fun HomeScreenContainer(
7164
}
7265
}
7366

74-
uiState.selectedRoutine?.let { routine ->
75-
if (uiState.routineDetailsBottomSheetVisible) {
76-
RoutineDetailsBottomSheet(
77-
routine = routine,
78-
onDismiss = { viewModel.sendIntent(HomeIntent.HideRoutineDetailsBottomSheet) },
79-
onEdit = { viewModel.sendIntent(HomeIntent.NavigateToEditRoutine(routine.routineId)) },
80-
onDelete = {
81-
if (routine.repeatDay.isEmpty()) {
82-
viewModel.deleteRoutineByDay(routine)
83-
} else {
84-
viewModel.sendIntent(HomeIntent.ShowDeleteConfirmDialog(routine))
85-
}
86-
},
87-
)
88-
}
89-
}
90-
91-
uiState.deletingRoutine?.let { routine ->
92-
if (uiState.showDeleteConfirmDialog) {
93-
DeleteConfirmDialog(
94-
onDeleteToday = {
95-
viewModel.deleteRoutineByDay(routine)
96-
viewModel.sendIntent(HomeIntent.HideDeleteConfirmDialog)
97-
},
98-
onDeleteAll = {
99-
viewModel.deleteRoutine(routine.routineId)
100-
},
101-
onDismiss = {
102-
viewModel.sendIntent(HomeIntent.HideDeleteConfirmDialog)
103-
},
104-
)
105-
}
106-
}
107-
10867
HomeScreen(
10968
uiState = uiState,
11069
onDateSelect = { date ->

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

Lines changed: 4 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import com.threegap.bitnagil.domain.emotion.usecase.GetEmotionChangeEventFlowUse
88
import com.threegap.bitnagil.domain.onboarding.usecase.GetOnBoardingRecommendRoutineEventFlowUseCase
99
import com.threegap.bitnagil.domain.routine.model.RoutineCompletion
1010
import com.threegap.bitnagil.domain.routine.model.RoutineCompletionInfo
11-
import com.threegap.bitnagil.domain.routine.usecase.DeleteRoutineByDayUseCase
12-
import com.threegap.bitnagil.domain.routine.usecase.DeleteRoutineUseCase
1311
import com.threegap.bitnagil.domain.routine.usecase.FetchWeeklyRoutinesUseCase
1412
import com.threegap.bitnagil.domain.routine.usecase.RoutineCompletionUseCase
1513
import com.threegap.bitnagil.domain.user.usecase.FetchUserProfileUseCase
@@ -20,7 +18,6 @@ import com.threegap.bitnagil.presentation.home.model.HomeSideEffect
2018
import com.threegap.bitnagil.presentation.home.model.HomeState
2119
import com.threegap.bitnagil.presentation.home.model.RoutineUiModel
2220
import com.threegap.bitnagil.presentation.home.model.RoutinesUiModel
23-
import com.threegap.bitnagil.presentation.home.model.toRoutineByDayDeletion
2421
import com.threegap.bitnagil.presentation.home.model.toUiModel
2522
import com.threegap.bitnagil.presentation.home.util.getCurrentWeekDays
2623
import dagger.hilt.android.lifecycle.HiltViewModel
@@ -42,8 +39,6 @@ class HomeViewModel @Inject constructor(
4239
private val fetchUserProfileUseCase: FetchUserProfileUseCase,
4340
private val fetchTodayEmotionUseCase: FetchTodayEmotionUseCase,
4441
private val routineCompletionUseCase: RoutineCompletionUseCase,
45-
private val deleteRoutineUseCase: DeleteRoutineUseCase,
46-
private val deleteRoutineByDayUseCase: DeleteRoutineByDayUseCase,
4742
private val getWriteRoutineEventFlowUseCase: GetWriteRoutineEventFlowUseCase,
4843
private val getEmotionChangeEventFlowUseCase: GetEmotionChangeEventFlowUseCase,
4944
private val getOnBoardingRecommendRoutineEventFlowUseCase: GetOnBoardingRecommendRoutineEventFlowUseCase,
@@ -63,7 +58,7 @@ class HomeViewModel @Inject constructor(
6358
observeRoutineUpdates()
6459
fetchWeeklyRoutines(container.stateFlow.value.currentWeeks)
6560
fetchUserProfile()
66-
getMyEmotion(container.stateFlow.value.selectedDate)
61+
fetchTodayEmotion(container.stateFlow.value.selectedDate)
6762
}
6863

6964
override suspend fun SimpleSyntax<HomeState, HomeSideEffect>.reduceState(
@@ -111,90 +106,12 @@ class HomeViewModel @Inject constructor(
111106
updateSubRoutine(state, intent.routineId, intent.subRoutineId, intent.isCompleted)
112107
}
113108

114-
is HomeIntent.DeleteRoutineOptimistically -> {
115-
val updatedRoutinesByDate = state.routines.routinesByDate.mapValues { (_, routineList) ->
116-
routineList.filterNot { it.routineId == intent.routineId }
117-
}
118-
119-
state.copy(
120-
routines = RoutinesUiModel(routinesByDate = updatedRoutinesByDate),
121-
showDeleteConfirmDialog = false,
122-
deletingRoutine = null,
123-
routineDetailsBottomSheetVisible = false,
124-
selectedRoutine = null,
125-
)
126-
}
127-
128-
is HomeIntent.RestoreRoutinesAfterDeleteFailure -> {
129-
state.copy(routines = intent.backupRoutines)
130-
}
131-
132-
is HomeIntent.ConfirmRoutineDeletion -> null
133-
134-
is HomeIntent.ShowRoutineDetailsBottomSheet -> {
135-
state.copy(
136-
routineDetailsBottomSheetVisible = true,
137-
selectedRoutine = intent.routine,
138-
)
139-
}
140-
141-
is HomeIntent.HideRoutineDetailsBottomSheet -> {
142-
state.copy(
143-
routineDetailsBottomSheetVisible = false,
144-
selectedRoutine = null,
145-
)
146-
}
147-
148-
is HomeIntent.ShowDeleteConfirmDialog -> {
149-
state.copy(
150-
showDeleteConfirmDialog = true,
151-
deletingRoutine = intent.routine,
152-
)
153-
}
154-
155-
is HomeIntent.HideDeleteConfirmDialog -> {
156-
state.copy(
157-
showDeleteConfirmDialog = false,
158-
deletingRoutine = null,
159-
)
160-
}
161-
162-
is HomeIntent.DeleteRoutineByDayOptimistically -> {
163-
val dateKey = intent.performedDate
164-
val updatedRoutinesByDate = state.routines.routinesByDate.toMutableMap()
165-
val routinesForDate = updatedRoutinesByDate[dateKey]?.toMutableList()
166-
167-
if (routinesForDate != null) {
168-
updatedRoutinesByDate[dateKey] = routinesForDate.filterNot {
169-
it.routineId == intent.routineId
170-
}
171-
}
172-
173-
state.copy(
174-
routines = RoutinesUiModel(routinesByDate = updatedRoutinesByDate),
175-
showDeleteConfirmDialog = false,
176-
deletingRoutine = null,
177-
routineDetailsBottomSheetVisible = false,
178-
selectedRoutine = null,
179-
)
180-
}
181-
182-
is HomeIntent.RestoreRoutinesAfterDeleteByDayFailure -> {
183-
state.copy(routines = intent.backupRoutines)
184-
}
185-
186-
is HomeIntent.ConfirmRoutineByDayDeletion -> null
187-
188109
is HomeIntent.LoadTodayEmotion -> {
189110
state.copy(todayEmotion = intent.emotion)
190111
}
191112

192113
is HomeIntent.OnRegisterEmotionClick -> {
193-
if (state.myEmotion == null) {
194-
sendSideEffect(HomeSideEffect.NavigateToEmotion)
195-
} else {
196-
sendSideEffect(HomeSideEffect.ShowToastWithIcon("선택한 감정 구슬이 이미 반영되었어요."))
197-
}
114+
sendSideEffect(HomeSideEffect.NavigateToEmotion)
198115
null
199116
}
200117

@@ -207,11 +124,6 @@ class HomeViewModel @Inject constructor(
207124
sendSideEffect(HomeSideEffect.ShowToast("루틴 완료 상태 저장에 실패했어요.\n다시 시도해 주세요."))
208125
null
209126
}
210-
211-
is HomeIntent.NavigateToEditRoutine -> {
212-
sendSideEffect(HomeSideEffect.NavigateToEditRoutine(intent.routineId))
213-
null
214-
}
215127
}
216128
return newState
217129
}
@@ -228,7 +140,7 @@ class HomeViewModel @Inject constructor(
228140
viewModelScope.launch {
229141
getEmotionChangeEventFlowUseCase().collect {
230142
val currentDate = LocalDate.now()
231-
getMyEmotion(currentDate)
143+
fetchTodayEmotion(currentDate)
232144
}
233145
}
234146
}
@@ -301,7 +213,7 @@ class HomeViewModel @Inject constructor(
301213
}
302214
}
303215

304-
private fun getMyEmotion(currentDate: LocalDate) {
216+
private fun fetchTodayEmotion(currentDate: LocalDate) {
305217
sendIntent(HomeIntent.UpdateLoading(true))
306218
viewModelScope.launch {
307219
fetchTodayEmotionUseCase(currentDate.toString()).fold(
@@ -494,52 +406,4 @@ class HomeViewModel @Inject constructor(
494406
},
495407
)
496408
}
497-
498-
fun deleteRoutine(routineId: String) {
499-
val currentRoutines = container.stateFlow.value.routines
500-
sendIntent(HomeIntent.DeleteRoutineOptimistically(routineId))
501-
502-
viewModelScope.launch {
503-
deleteRoutineUseCase(routineId).fold(
504-
onSuccess = {
505-
sendIntent(HomeIntent.ConfirmRoutineDeletion(routineId))
506-
},
507-
onFailure = { error ->
508-
Log.e("HomeViewModel", "루틴 삭제 실패: ${error.message}")
509-
sendIntent(HomeIntent.RestoreRoutinesAfterDeleteFailure(currentRoutines))
510-
},
511-
)
512-
}
513-
}
514-
515-
fun deleteRoutineByDay(routineUiModel: RoutineUiModel) {
516-
val currentRoutines = container.stateFlow.value.routines
517-
val performedDate = container.stateFlow.value.selectedDate.toString()
518-
519-
sendIntent(
520-
HomeIntent.DeleteRoutineByDayOptimistically(
521-
routineId = routineUiModel.routineId,
522-
performedDate = performedDate,
523-
),
524-
)
525-
526-
viewModelScope.launch {
527-
val routineByDayDeletion = routineUiModel.toRoutineByDayDeletion(performedDate)
528-
529-
deleteRoutineByDayUseCase(routineByDayDeletion).fold(
530-
onSuccess = {
531-
sendIntent(
532-
HomeIntent.ConfirmRoutineByDayDeletion(
533-
routineId = routineUiModel.routineId,
534-
performedDate = performedDate,
535-
),
536-
)
537-
},
538-
onFailure = {
539-
Log.e("HomeViewModel", "루틴 삭제 실패: ${it.message}")
540-
sendIntent(HomeIntent.RestoreRoutinesAfterDeleteByDayFailure(currentRoutines))
541-
},
542-
)
543-
}
544-
}
545409
}

0 commit comments

Comments
 (0)