diff --git a/presentation/src/main/java/com/threegap/bitnagil/presentation/routinelist/RoutineListViewModel.kt b/presentation/src/main/java/com/threegap/bitnagil/presentation/routinelist/RoutineListViewModel.kt index e61e2e57..367317c3 100644 --- a/presentation/src/main/java/com/threegap/bitnagil/presentation/routinelist/RoutineListViewModel.kt +++ b/presentation/src/main/java/com/threegap/bitnagil/presentation/routinelist/RoutineListViewModel.kt @@ -6,6 +6,7 @@ import androidx.lifecycle.viewModelScope import com.threegap.bitnagil.domain.routine.usecase.DeleteRoutineForDayUseCase import com.threegap.bitnagil.domain.routine.usecase.DeleteRoutineUseCase import com.threegap.bitnagil.domain.routine.usecase.FetchWeeklyRoutinesUseCase +import com.threegap.bitnagil.domain.writeroutine.usecase.GetWriteRoutineEventFlowUseCase import com.threegap.bitnagil.presentation.common.mviviewmodel.MviViewModel import com.threegap.bitnagil.presentation.home.util.getCurrentWeekDays import com.threegap.bitnagil.presentation.routinelist.model.RoutineListIntent @@ -24,6 +25,7 @@ class RoutineListViewModel @Inject constructor( private val fetchWeeklyRoutinesUseCase: FetchWeeklyRoutinesUseCase, private val deleteRoutineUseCase: DeleteRoutineUseCase, private val deleteRoutineForDayUseCase: DeleteRoutineForDayUseCase, + private val getWriteRoutineEventFlowUseCase: GetWriteRoutineEventFlowUseCase, ) : MviViewModel( savedStateHandle = savedStateHandle, initState = RoutineListState( @@ -38,6 +40,7 @@ class RoutineListViewModel @Inject constructor( init { fetchRoutines() + observeRoutineChanges() } override suspend fun SimpleSyntax.reduceState( @@ -114,6 +117,14 @@ class RoutineListViewModel @Inject constructor( return newState } + private fun observeRoutineChanges() { + viewModelScope.launch { + getWriteRoutineEventFlowUseCase().collect { + fetchRoutines() + } + } + } + private fun fetchRoutines() { sendIntent(RoutineListIntent.UpdateLoading(true)) val currentWeek = stateFlow.value.selectedDate.getCurrentWeekDays()