Skip to content

Commit b7cf1c7

Browse files
committed
[BOOK-212] feat: 도서 기록 조회 정렬 기능 구현
1 parent 5660bb3 commit b7cf1c7

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

feature/detail/src/main/kotlin/com/ninecraft/booket/feature/detail/book/BookDetailPresenter.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,13 @@ class BookDetailPresenter @AssistedInject constructor(
150150
readingRecords = if (startIndex == START_INDEX) {
151151
result.content.toPersistentList()
152152
} else {
153-
(readingRecords + result.content).toPersistentList()
153+
// 새로운 데이터를 기존 리스트와 합친 후 정렬
154+
(readingRecords + result.content).sortedWith(
155+
when (currentRecordSort) {
156+
RecordSort.PAGE_NUMBER_ASC -> compareBy { it.pageNumber }
157+
RecordSort.CREATED_DATE_DESC -> compareByDescending { it.createdAt }
158+
}
159+
).toPersistentList()
154160
}
155161

156162
currentStartIndex = startIndex
@@ -219,6 +225,12 @@ class BookDetailPresenter @AssistedInject constructor(
219225

220226
is BookDetailUiEvent.OnRecordSortItemSelected -> {
221227
currentRecordSort = event.sortType
228+
readingRecords = readingRecords.sortedWith(
229+
when (event.sortType) {
230+
RecordSort.PAGE_NUMBER_ASC -> compareBy { it.pageNumber }
231+
RecordSort.CREATED_DATE_DESC -> compareByDescending { it.createdAt }
232+
}
233+
).toPersistentList()
222234
isRecordSortBottomSheetVisible = false
223235
}
224236

0 commit comments

Comments
 (0)