Skip to content

Commit

Permalink
fix/#131: LectureEvaluation - 개설학과 필터링 race condition 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
jinukeu committed Feb 9, 2024
1 parent 5afce01 commit e523e7a
Showing 1 changed file with 28 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import kotlinx.coroutines.sync.withLock
import org.orbitmvi.orbit.Container
import org.orbitmvi.orbit.ContainerHost
import org.orbitmvi.orbit.annotation.OrbitExperimental
import org.orbitmvi.orbit.syntax.simple.SimpleSyntax
import org.orbitmvi.orbit.syntax.simple.blockingIntent
import org.orbitmvi.orbit.syntax.simple.intent
import org.orbitmvi.orbit.syntax.simple.postSideEffect
Expand Down Expand Up @@ -51,15 +52,27 @@ class LectureEvaluationViewModel @Inject constructor(

fun updateSelectedOpenMajor(openMajor: String) = intent {
if (openMajor == state.selectedOpenMajor) return@intent

reduce {
state.copy(
selectedOpenMajor = openMajor,
)
}

getLectureEvaluationList(
majorType = openMajor,
needClear = true,
)
}

fun updateAlignItem(position: Int) {
fun updateAlignItem(position: Int) = intent {

reduce {
state.copy(
selectedAlignPosition = position,
)
}

getLectureEvaluationList(
alignPosition = position,
needClear = true,
)
}
Expand All @@ -81,8 +94,6 @@ class LectureEvaluationViewModel @Inject constructor(

fun getLectureEvaluationList(
search: String = searchQuery,
alignPosition: Int = currentState.selectedAlignPosition,
majorType: String = currentState.selectedOpenMajor,
needClear: Boolean,
) = intent {
mutex.withLock {
Expand All @@ -97,14 +108,12 @@ class LectureEvaluationViewModel @Inject constructor(
getLectureEvaluationListUseCase(
RetrieveLectureEvaluationAverageListUseCase.Param(
search = search,
option = LectureAlign.entries[alignPosition].query,
option = LectureAlign.entries[currentState.selectedAlignPosition].query,
page = page,
majorType = majorType,
majorType = currentState.selectedOpenMajor,
),
).onSuccess { newList ->
handleGetLectureEvaluationListSuccess(
alignPosition = alignPosition,
majorType = majorType,
currentList = currentList,
newList = newList,
)
Expand All @@ -119,25 +128,20 @@ class LectureEvaluationViewModel @Inject constructor(
}
}

private fun handleGetLectureEvaluationListSuccess(
alignPosition: Int,
majorType: String,
private suspend fun SimpleSyntax<LectureEvaluationState, LectureEvaluationSideEffect>.handleGetLectureEvaluationListSuccess(
currentList: List<LectureEvaluationAverage?>,
newList: List<LectureEvaluationAverage?>,
) = intent {
reduce {
page++
state.copy(
selectedAlignPosition = alignPosition,
selectedOpenMajor = majorType,
lectureEvaluationList = currentList
.plus(newList)
.distinctBy { it?.id }
.toPersistentList(),
)
}
) = reduce {
page++
state.copy(
lectureEvaluationList = currentList
.plus(newList)
.distinctBy { it?.id }
.toPersistentList(),
)
}


private suspend fun checkLoggedIn() {
isLoggedIn = getUserInfoUseCase().catch { }.lastOrNull()?.isLoggedIn == true
}
Expand Down

0 comments on commit e523e7a

Please sign in to comment.