diff --git a/feature/lectureevaluation/viewerreporter/src/main/java/com/suwiki/feature/lectureevaluation/viewerreporter/LectureEvaluationViewModel.kt b/feature/lectureevaluation/viewerreporter/src/main/java/com/suwiki/feature/lectureevaluation/viewerreporter/LectureEvaluationViewModel.kt index a2f74d76..8e2be776 100644 --- a/feature/lectureevaluation/viewerreporter/src/main/java/com/suwiki/feature/lectureevaluation/viewerreporter/LectureEvaluationViewModel.kt +++ b/feature/lectureevaluation/viewerreporter/src/main/java/com/suwiki/feature/lectureevaluation/viewerreporter/LectureEvaluationViewModel.kt @@ -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 @@ -51,15 +52,26 @@ 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, ) } @@ -81,8 +93,6 @@ class LectureEvaluationViewModel @Inject constructor( fun getLectureEvaluationList( search: String = searchQuery, - alignPosition: Int = currentState.selectedAlignPosition, - majorType: String = currentState.selectedOpenMajor, needClear: Boolean, ) = intent { mutex.withLock { @@ -97,14 +107,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, ) @@ -119,23 +127,17 @@ class LectureEvaluationViewModel @Inject constructor( } } - private fun handleGetLectureEvaluationListSuccess( - alignPosition: Int, - majorType: String, + private suspend fun SimpleSyntax.handleGetLectureEvaluationListSuccess( currentList: List, newList: List, - ) = 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() { diff --git a/feature/timetable/src/main/java/com/suwiki/feature/timetable/openlecture/OpenLectureViewModel.kt b/feature/timetable/src/main/java/com/suwiki/feature/timetable/openlecture/OpenLectureViewModel.kt index 68697d52..3a4989c9 100644 --- a/feature/timetable/src/main/java/com/suwiki/feature/timetable/openlecture/OpenLectureViewModel.kt +++ b/feature/timetable/src/main/java/com/suwiki/feature/timetable/openlecture/OpenLectureViewModel.kt @@ -18,6 +18,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 @@ -52,6 +53,7 @@ class OpenLectureViewModel @Inject constructor( OpenLectureSideEffect.NavigateCellEditor(openLecture.toCellEditorArgument()), ) } + fun navigateAddCustomCell() = intent { postSideEffect(OpenLectureSideEffect.NavigateAddCustomTimetableCell) } fun insertTimetable() = intent { @@ -128,24 +130,33 @@ class OpenLectureViewModel @Inject constructor( } fun updateSchoolLevelPosition(schoolLevel: SchoolLevel) = intent { + reduce { + state.copy( + schoolLevel = schoolLevel, + ) + } + getOpenLectureList( - schoolLevel = schoolLevel, needClear = true, ) } fun updateSelectedOpenMajor(openMajor: String) = intent { if (openMajor == state.selectedOpenMajor) return@intent + + reduce { + state.copy( + selectedOpenMajor = openMajor, + ) + } + getOpenLectureList( - majorType = openMajor, needClear = true, ) } fun getOpenLectureList( search: String = searchQuery, - schoolLevel: SchoolLevel = currentState.schoolLevel, - majorType: String = currentState.selectedOpenMajor, needClear: Boolean, ) = intent { mutex.withLock { @@ -165,13 +176,11 @@ class OpenLectureViewModel @Inject constructor( GetOpenLectureListUseCase.Param( cursorId = cursorId, keyword = search, - major = if (majorType == "전체") null else majorType, - grade = schoolLevel.query, + major = if (currentState.selectedOpenMajor == "전체") null else currentState.selectedOpenMajor, + grade = currentState.schoolLevel.query, ), ).onSuccess { newData -> handleGetOpenLectureListSuccess( - schoolLevel = schoolLevel, - majorType = majorType, currentList = currentList, newData = newData, ) @@ -186,24 +195,18 @@ class OpenLectureViewModel @Inject constructor( } } - private fun handleGetOpenLectureListSuccess( - schoolLevel: SchoolLevel, - majorType: String, + private suspend fun SimpleSyntax.handleGetOpenLectureListSuccess( currentList: List, newData: OpenLectureData, - ) = intent { - reduce { - isLast = newData.isLast - cursorId = newData.content.lastOrNull()?.id ?: 0L - state.copy( - schoolLevel = schoolLevel, - selectedOpenMajor = majorType, - openLectureList = currentList - .plus(newData.content) - .distinctBy { it.id } - .toPersistentList(), - ) - } + ) = reduce { + isLast = newData.isLast + cursorId = newData.content.lastOrNull()?.id ?: 0L + state.copy( + openLectureList = currentList + .plus(newData.content) + .distinctBy { it.id } + .toPersistentList(), + ) } fun showGradeBottomSheet() = intent { reduce { state.copy(showSchoolLevelBottomSheet = true) } }