Skip to content

Commit 89fdbbd

Browse files
committed
[BOOK-212] feat: 도서 기록 등록 시간 비교를 위한 LocalDateTime 파싱 적용
1 parent 4d0d3eb commit 89fdbbd

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import kotlinx.collections.immutable.persistentListOf
3333
import kotlinx.collections.immutable.toImmutableList
3434
import kotlinx.collections.immutable.toPersistentList
3535
import kotlinx.coroutines.launch
36+
import java.time.LocalDateTime
3637

3738
class BookDetailPresenter @AssistedInject constructor(
3839
@Assisted private val screen: BookDetailScreen,
@@ -45,6 +46,13 @@ class BookDetailPresenter @AssistedInject constructor(
4546
private const val START_INDEX = 0
4647
}
4748

49+
private fun getRecordComparator(sortType: RecordSort): Comparator<ReadingRecordModel> {
50+
return when (sortType) {
51+
RecordSort.PAGE_NUMBER_ASC -> compareBy { it.pageNumber }
52+
RecordSort.CREATED_DATE_DESC -> compareByDescending { LocalDateTime.parse(it.createdAt) }
53+
}
54+
}
55+
4856
@Composable
4957
override fun present(): BookDetailUiState {
5058
val scope = rememberCoroutineScope()
@@ -150,13 +158,7 @@ class BookDetailPresenter @AssistedInject constructor(
150158
readingRecords = if (startIndex == START_INDEX) {
151159
result.content.toPersistentList()
152160
} else {
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()
161+
(readingRecords + result.content).toPersistentList()
160162
}
161163

162164
currentStartIndex = startIndex
@@ -225,12 +227,7 @@ class BookDetailPresenter @AssistedInject constructor(
225227

226228
is BookDetailUiEvent.OnRecordSortItemSelected -> {
227229
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()
230+
readingRecords = readingRecords.sortedWith(getRecordComparator(event.sortType)).toPersistentList()
234231
isRecordSortBottomSheetVisible = false
235232
}
236233

0 commit comments

Comments
 (0)