Skip to content

Commit

Permalink
fix: Prevent API call on re-filter selection
Browse files Browse the repository at this point in the history
  • Loading branch information
HamzaIsrar12 committed Jul 19, 2024
1 parent 423af47 commit ccfce12
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ fun AllEnrolledCoursesView(
}

is AllEnrolledCoursesAction.FilterChange -> {
viewModel.getCourses(action.courseStatusFilter)
viewModel.changeFilter(action.courseStatusFilter)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class AllEnrolledCoursesViewModel(
val uiMessage: SharedFlow<UIMessage>
get() = _uiMessage.asSharedFlow()

private val currentFilter: MutableStateFlow<CourseStatusFilter> = MutableStateFlow(CourseStatusFilter.ALL)
private val currentFilter: MutableStateFlow<CourseStatusFilter> =
MutableStateFlow(CourseStatusFilter.ALL)

private var job: Job? = null

Expand All @@ -67,6 +68,12 @@ class AllEnrolledCoursesViewModel(
internalLoadingCourses(courseStatusFilter ?: currentFilter.value)
}

fun changeFilter(courseStatusFilter: CourseStatusFilter?) {
if (courseStatusFilter != currentFilter.value) {
getCourses(courseStatusFilter)
}
}

fun updateCourses() {
viewModelScope.launch {
try {
Expand Down

0 comments on commit ccfce12

Please sign in to comment.