Skip to content

Commit a23aa5f

Browse files
authored
Merge pull request #132 from uswLectureEvaluation/fix/#131-openmajor-filter
Fix/#131 개설강좌 필터링 문제 해결
2 parents ac7cbcc + 111469c commit a23aa5f

File tree

2 files changed

+53
-48
lines changed

2 files changed

+53
-48
lines changed

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

Lines changed: 26 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,26 @@ 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+
reduce {
69+
state.copy(
70+
selectedAlignPosition = position,
71+
)
72+
}
73+
6174
getLectureEvaluationList(
62-
alignPosition = position,
6375
needClear = true,
6476
)
6577
}
@@ -81,8 +93,6 @@ class LectureEvaluationViewModel @Inject constructor(
8193

8294
fun getLectureEvaluationList(
8395
search: String = searchQuery,
84-
alignPosition: Int = currentState.selectedAlignPosition,
85-
majorType: String = currentState.selectedOpenMajor,
8696
needClear: Boolean,
8797
) = intent {
8898
mutex.withLock {
@@ -97,14 +107,12 @@ class LectureEvaluationViewModel @Inject constructor(
97107
getLectureEvaluationListUseCase(
98108
RetrieveLectureEvaluationAverageListUseCase.Param(
99109
search = search,
100-
option = LectureAlign.entries[alignPosition].query,
110+
option = LectureAlign.entries[currentState.selectedAlignPosition].query,
101111
page = page,
102-
majorType = majorType,
112+
majorType = currentState.selectedOpenMajor,
103113
),
104114
).onSuccess { newList ->
105115
handleGetLectureEvaluationListSuccess(
106-
alignPosition = alignPosition,
107-
majorType = majorType,
108116
currentList = currentList,
109117
newList = newList,
110118
)
@@ -119,23 +127,17 @@ class LectureEvaluationViewModel @Inject constructor(
119127
}
120128
}
121129

122-
private fun handleGetLectureEvaluationListSuccess(
123-
alignPosition: Int,
124-
majorType: String,
130+
private suspend fun SimpleSyntax<LectureEvaluationState, LectureEvaluationSideEffect>.handleGetLectureEvaluationListSuccess(
125131
currentList: List<LectureEvaluationAverage?>,
126132
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-
}
133+
) = reduce {
134+
page++
135+
state.copy(
136+
lectureEvaluationList = currentList
137+
.plus(newList)
138+
.distinctBy { it?.id }
139+
.toPersistentList(),
140+
)
139141
}
140142

141143
private suspend fun checkLoggedIn() {

feature/timetable/src/main/java/com/suwiki/feature/timetable/openlecture/OpenLectureViewModel.kt

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import kotlinx.coroutines.sync.withLock
1818
import org.orbitmvi.orbit.Container
1919
import org.orbitmvi.orbit.ContainerHost
2020
import org.orbitmvi.orbit.annotation.OrbitExperimental
21+
import org.orbitmvi.orbit.syntax.simple.SimpleSyntax
2122
import org.orbitmvi.orbit.syntax.simple.blockingIntent
2223
import org.orbitmvi.orbit.syntax.simple.intent
2324
import org.orbitmvi.orbit.syntax.simple.postSideEffect
@@ -52,6 +53,7 @@ class OpenLectureViewModel @Inject constructor(
5253
OpenLectureSideEffect.NavigateCellEditor(openLecture.toCellEditorArgument()),
5354
)
5455
}
56+
5557
fun navigateAddCustomCell() = intent { postSideEffect(OpenLectureSideEffect.NavigateAddCustomTimetableCell) }
5658

5759
fun insertTimetable() = intent {
@@ -128,24 +130,33 @@ class OpenLectureViewModel @Inject constructor(
128130
}
129131

130132
fun updateSchoolLevelPosition(schoolLevel: SchoolLevel) = intent {
133+
reduce {
134+
state.copy(
135+
schoolLevel = schoolLevel,
136+
)
137+
}
138+
131139
getOpenLectureList(
132-
schoolLevel = schoolLevel,
133140
needClear = true,
134141
)
135142
}
136143

137144
fun updateSelectedOpenMajor(openMajor: String) = intent {
138145
if (openMajor == state.selectedOpenMajor) return@intent
146+
147+
reduce {
148+
state.copy(
149+
selectedOpenMajor = openMajor,
150+
)
151+
}
152+
139153
getOpenLectureList(
140-
majorType = openMajor,
141154
needClear = true,
142155
)
143156
}
144157

145158
fun getOpenLectureList(
146159
search: String = searchQuery,
147-
schoolLevel: SchoolLevel = currentState.schoolLevel,
148-
majorType: String = currentState.selectedOpenMajor,
149160
needClear: Boolean,
150161
) = intent {
151162
mutex.withLock {
@@ -165,13 +176,11 @@ class OpenLectureViewModel @Inject constructor(
165176
GetOpenLectureListUseCase.Param(
166177
cursorId = cursorId,
167178
keyword = search,
168-
major = if (majorType == "전체") null else majorType,
169-
grade = schoolLevel.query,
179+
major = if (currentState.selectedOpenMajor == "전체") null else currentState.selectedOpenMajor,
180+
grade = currentState.schoolLevel.query,
170181
),
171182
).onSuccess { newData ->
172183
handleGetOpenLectureListSuccess(
173-
schoolLevel = schoolLevel,
174-
majorType = majorType,
175184
currentList = currentList,
176185
newData = newData,
177186
)
@@ -186,24 +195,18 @@ class OpenLectureViewModel @Inject constructor(
186195
}
187196
}
188197

189-
private fun handleGetOpenLectureListSuccess(
190-
schoolLevel: SchoolLevel,
191-
majorType: String,
198+
private suspend fun SimpleSyntax<OpenLectureState, OpenLectureSideEffect>.handleGetOpenLectureListSuccess(
192199
currentList: List<OpenLecture>,
193200
newData: OpenLectureData,
194-
) = intent {
195-
reduce {
196-
isLast = newData.isLast
197-
cursorId = newData.content.lastOrNull()?.id ?: 0L
198-
state.copy(
199-
schoolLevel = schoolLevel,
200-
selectedOpenMajor = majorType,
201-
openLectureList = currentList
202-
.plus(newData.content)
203-
.distinctBy { it.id }
204-
.toPersistentList(),
205-
)
206-
}
201+
) = reduce {
202+
isLast = newData.isLast
203+
cursorId = newData.content.lastOrNull()?.id ?: 0L
204+
state.copy(
205+
openLectureList = currentList
206+
.plus(newData.content)
207+
.distinctBy { it.id }
208+
.toPersistentList(),
209+
)
207210
}
208211

209212
fun showGradeBottomSheet() = intent { reduce { state.copy(showSchoolLevelBottomSheet = true) } }

0 commit comments

Comments
 (0)