@@ -14,6 +14,7 @@ import kotlinx.coroutines.sync.withLock
14
14
import org.orbitmvi.orbit.Container
15
15
import org.orbitmvi.orbit.ContainerHost
16
16
import org.orbitmvi.orbit.annotation.OrbitExperimental
17
+ import org.orbitmvi.orbit.syntax.simple.SimpleSyntax
17
18
import org.orbitmvi.orbit.syntax.simple.blockingIntent
18
19
import org.orbitmvi.orbit.syntax.simple.intent
19
20
import org.orbitmvi.orbit.syntax.simple.postSideEffect
@@ -51,15 +52,27 @@ class LectureEvaluationViewModel @Inject constructor(
51
52
52
53
fun updateSelectedOpenMajor (openMajor : String ) = intent {
53
54
if (openMajor == state.selectedOpenMajor) return @intent
55
+
56
+ reduce {
57
+ state.copy(
58
+ selectedOpenMajor = openMajor,
59
+ )
60
+ }
61
+
54
62
getLectureEvaluationList(
55
- majorType = openMajor,
56
63
needClear = true ,
57
64
)
58
65
}
59
66
60
- fun updateAlignItem (position : Int ) {
67
+ fun updateAlignItem (position : Int ) = intent {
68
+
69
+ reduce {
70
+ state.copy(
71
+ selectedAlignPosition = position,
72
+ )
73
+ }
74
+
61
75
getLectureEvaluationList(
62
- alignPosition = position,
63
76
needClear = true ,
64
77
)
65
78
}
@@ -81,8 +94,6 @@ class LectureEvaluationViewModel @Inject constructor(
81
94
82
95
fun getLectureEvaluationList (
83
96
search : String = searchQuery,
84
- alignPosition : Int = currentState.selectedAlignPosition,
85
- majorType : String = currentState.selectedOpenMajor,
86
97
needClear : Boolean ,
87
98
) = intent {
88
99
mutex.withLock {
@@ -97,14 +108,12 @@ class LectureEvaluationViewModel @Inject constructor(
97
108
getLectureEvaluationListUseCase(
98
109
RetrieveLectureEvaluationAverageListUseCase .Param (
99
110
search = search,
100
- option = LectureAlign .entries[alignPosition ].query,
111
+ option = LectureAlign .entries[currentState.selectedAlignPosition ].query,
101
112
page = page,
102
- majorType = majorType ,
113
+ majorType = currentState.selectedOpenMajor ,
103
114
),
104
115
).onSuccess { newList ->
105
116
handleGetLectureEvaluationListSuccess(
106
- alignPosition = alignPosition,
107
- majorType = majorType,
108
117
currentList = currentList,
109
118
newList = newList,
110
119
)
@@ -119,25 +128,20 @@ class LectureEvaluationViewModel @Inject constructor(
119
128
}
120
129
}
121
130
122
- private fun handleGetLectureEvaluationListSuccess (
123
- alignPosition : Int ,
124
- majorType : String ,
131
+ private suspend fun SimpleSyntax <LectureEvaluationState , LectureEvaluationSideEffect >.handleGetLectureEvaluationListSuccess (
125
132
currentList : List <LectureEvaluationAverage ?>,
126
133
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
+ )
139
142
}
140
143
144
+
141
145
private suspend fun checkLoggedIn () {
142
146
isLoggedIn = getUserInfoUseCase().catch { }.lastOrNull()?.isLoggedIn == true
143
147
}
0 commit comments