Skip to content

Commit e523e7a

Browse files
committed
fix/#131: LectureEvaluation - 개설학과 필터링 race condition 해결
1 parent 5afce01 commit e523e7a

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

feature/lectureevaluation/viewerreporter/src/main/java/com/suwiki/feature/lectureevaluation/viewerreporter/LectureEvaluationViewModel.kt

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import kotlinx.coroutines.sync.withLock
1414
import org.orbitmvi.orbit.Container
1515
import org.orbitmvi.orbit.ContainerHost
1616
import org.orbitmvi.orbit.annotation.OrbitExperimental
17+
import org.orbitmvi.orbit.syntax.simple.SimpleSyntax
1718
import org.orbitmvi.orbit.syntax.simple.blockingIntent
1819
import org.orbitmvi.orbit.syntax.simple.intent
1920
import org.orbitmvi.orbit.syntax.simple.postSideEffect
@@ -51,15 +52,27 @@ class LectureEvaluationViewModel @Inject constructor(
5152

5253
fun updateSelectedOpenMajor(openMajor: String) = intent {
5354
if (openMajor == state.selectedOpenMajor) return@intent
55+
56+
reduce {
57+
state.copy(
58+
selectedOpenMajor = openMajor,
59+
)
60+
}
61+
5462
getLectureEvaluationList(
55-
majorType = openMajor,
5663
needClear = true,
5764
)
5865
}
5966

60-
fun updateAlignItem(position: Int) {
67+
fun updateAlignItem(position: Int) = intent {
68+
69+
reduce {
70+
state.copy(
71+
selectedAlignPosition = position,
72+
)
73+
}
74+
6175
getLectureEvaluationList(
62-
alignPosition = position,
6376
needClear = true,
6477
)
6578
}
@@ -81,8 +94,6 @@ class LectureEvaluationViewModel @Inject constructor(
8194

8295
fun getLectureEvaluationList(
8396
search: String = searchQuery,
84-
alignPosition: Int = currentState.selectedAlignPosition,
85-
majorType: String = currentState.selectedOpenMajor,
8697
needClear: Boolean,
8798
) = intent {
8899
mutex.withLock {
@@ -97,14 +108,12 @@ class LectureEvaluationViewModel @Inject constructor(
97108
getLectureEvaluationListUseCase(
98109
RetrieveLectureEvaluationAverageListUseCase.Param(
99110
search = search,
100-
option = LectureAlign.entries[alignPosition].query,
111+
option = LectureAlign.entries[currentState.selectedAlignPosition].query,
101112
page = page,
102-
majorType = majorType,
113+
majorType = currentState.selectedOpenMajor,
103114
),
104115
).onSuccess { newList ->
105116
handleGetLectureEvaluationListSuccess(
106-
alignPosition = alignPosition,
107-
majorType = majorType,
108117
currentList = currentList,
109118
newList = newList,
110119
)
@@ -119,25 +128,20 @@ class LectureEvaluationViewModel @Inject constructor(
119128
}
120129
}
121130

122-
private fun handleGetLectureEvaluationListSuccess(
123-
alignPosition: Int,
124-
majorType: String,
131+
private suspend fun SimpleSyntax<LectureEvaluationState, LectureEvaluationSideEffect>.handleGetLectureEvaluationListSuccess(
125132
currentList: List<LectureEvaluationAverage?>,
126133
newList: List<LectureEvaluationAverage?>,
127-
) = intent {
128-
reduce {
129-
page++
130-
state.copy(
131-
selectedAlignPosition = alignPosition,
132-
selectedOpenMajor = majorType,
133-
lectureEvaluationList = currentList
134-
.plus(newList)
135-
.distinctBy { it?.id }
136-
.toPersistentList(),
137-
)
138-
}
134+
) = reduce {
135+
page++
136+
state.copy(
137+
lectureEvaluationList = currentList
138+
.plus(newList)
139+
.distinctBy { it?.id }
140+
.toPersistentList(),
141+
)
139142
}
140143

144+
141145
private suspend fun checkLoggedIn() {
142146
isLoggedIn = getUserInfoUseCase().catch { }.lastOrNull()?.isLoggedIn == true
143147
}

0 commit comments

Comments
 (0)