Skip to content

Commit

Permalink
fix selected day
Browse files Browse the repository at this point in the history
  • Loading branch information
X1nto committed Dec 23, 2023
1 parent b1ad45e commit 10d6b09
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ class HomeViewModel(
private val lecturesRepository: LecturesRepository
) : ViewModel() {

private val _selectedDay = MutableStateFlow(LocalDate.now().dayOfWeek.value - 1)
private val _selectedDay = MutableStateFlow(LocalDate.now().dayOfWeek.ordinal)

val state =
combine(lecturesRepository.observeLectures(), _selectedDay) { lectures, selectedDay ->
when (lectures) {
is DomainResponse.Loading -> HomeState.Loading
is DomainResponse.Success -> {
val selectedIndex = if (selectedDay > lectures.value.size) 0 else selectedDay
val selectedIndex = if (selectedDay >= lectures.value.size) 0 else selectedDay
HomeState.Success(
selectedDay = selectedIndex,
lectures = lectures.value
Expand Down

0 comments on commit 10d6b09

Please sign in to comment.