Skip to content

Commit

Permalink
feat : #72 검색기능 구현 완료
Browse files Browse the repository at this point in the history
  • Loading branch information
lsakee committed Jan 3, 2024
1 parent d17645b commit 9e9f566
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.suwiki.core.ui.extension

import android.util.Log
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
Expand All @@ -22,17 +23,26 @@ fun LazyListState.OnBottomReached(
val shouldLoadMore = remember {
derivedStateOf {
val lastVisibleItem = layoutInfo.visibleItemsInfo.lastOrNull()
?: return@derivedStateOf true

// subtract buffer from the total items
if (lastVisibleItem == null) {
Log.d("Sak","list = null ")
return@derivedStateOf true
}

lastVisibleItem.index >= layoutInfo.totalItemsCount - 1 - buffer
}
}

LaunchedEffect(shouldLoadMore) {
Log.d("Sak","$shouldLoadMore ")
LaunchedEffect(shouldLoadMore.value) {
snapshotFlow { shouldLoadMore.value }
.collect { if (it) onLoadMore() }
.collect {
if (it) {
Log.d("Sak"," Get Data")
onLoadMore()
}
}
}
}

fun LazyListState.isScrolledToEnd() = layoutInfo.visibleItemsInfo.lastOrNull()?.index == layoutInfo.totalItemsCount - 1

Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fun LectureEvaluationRoute(
}

allLectureEvaluationListState.OnBottomReached {
viewModel.getLectureEvaluationList(selectedOpenMajor)
viewModel.getLectureEvaluationList()
}

LectureEvaluationScreen(
Expand Down Expand Up @@ -175,7 +175,7 @@ private fun LectureEvaluationLazyColumn(
) {
items(
items = openLectureEvaluationInfoList,
key = { it!!.id },
key = { it?.id ?:1 },
) { lectureEvaluation ->
with(lectureEvaluation) {
SuwikiClassReviewCard(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class LectureEvaluationViewModel @Inject constructor(
@OptIn(OrbitExperimental::class)
fun updateSearchValue(searchValue: String) = blockingIntent {
reduce { state.copy(searchValue = searchValue) }
getLectureEvaluationList()
setFilterLectureEvaluationList()
}

Expand Down Expand Up @@ -67,13 +68,13 @@ class LectureEvaluationViewModel @Inject constructor(
}
}

fun getLectureEvaluationList(majorType: String) = intent {
fun getLectureEvaluationList() = intent {
getLectureEvaluationListUseCase(
RetrieveLectureEvaluationAverageListUseCase.Param(
container.stateFlow.value.searchValue,
container.stateFlow.value.selectedFilterValue(),
loadMoreCounter,
majorType,
container.stateFlow.value.selectedOpenMajor,
),
)
.onSuccess {
Expand Down

0 comments on commit 9e9f566

Please sign in to comment.