Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<RoutineListState, RoutineListSideEffect, RoutineListIntent>(
savedStateHandle = savedStateHandle,
initState = RoutineListState(
Expand All @@ -38,6 +40,7 @@ class RoutineListViewModel @Inject constructor(

init {
fetchRoutines()
observeRoutineChanges()
}
Comment thread
wjdrjs00 marked this conversation as resolved.

override suspend fun SimpleSyntax<RoutineListState, RoutineListSideEffect>.reduceState(
Expand Down Expand Up @@ -114,6 +117,14 @@ class RoutineListViewModel @Inject constructor(
return newState
}

private fun observeRoutineChanges() {
viewModelScope.launch {
getWriteRoutineEventFlowUseCase().collect {
fetchRoutines()
}
}
}
Comment thread
wjdrjs00 marked this conversation as resolved.

private fun fetchRoutines() {
sendIntent(RoutineListIntent.UpdateLoading(true))
val currentWeek = stateFlow.value.selectedDate.getCurrentWeekDays()
Expand Down