Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/#131 개설강좌 필터링 문제 해결 #132

Merged
merged 3 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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,
)
}
Expand All @@ -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 {
Expand All @@ -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,
)
Expand All @@ -119,23 +127,17 @@ 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -52,6 +53,7 @@ class OpenLectureViewModel @Inject constructor(
OpenLectureSideEffect.NavigateCellEditor(openLecture.toCellEditorArgument()),
)
}

fun navigateAddCustomCell() = intent { postSideEffect(OpenLectureSideEffect.NavigateAddCustomTimetableCell) }

fun insertTimetable() = intent {
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
)
Expand All @@ -186,24 +195,18 @@ class OpenLectureViewModel @Inject constructor(
}
}

private fun handleGetOpenLectureListSuccess(
schoolLevel: SchoolLevel,
majorType: String,
private suspend fun SimpleSyntax<OpenLectureState, OpenLectureSideEffect>.handleGetOpenLectureListSuccess(
currentList: List<OpenLecture>,
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) } }
Expand Down
Loading