mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-17 21:27:01 +05:30
app: revise saved posts sorting logic again
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
995eba2c11
commit
314aba6d65
1 changed files with 8 additions and 11 deletions
|
@ -35,7 +35,7 @@ fun SavedPosts(
|
|||
) {
|
||||
val listState = rememberLazyListState()
|
||||
val urlLauncher = LocalUrlLauncher.current
|
||||
val sortOrder by sortReversed.collectAsState(false)
|
||||
val reverseSort by sortReversed.collectAsState(false)
|
||||
|
||||
if (posts.isEmpty()) {
|
||||
Column(
|
||||
|
@ -56,19 +56,16 @@ fun SavedPosts(
|
|||
state = listState,
|
||||
modifier = Modifier.then(modifier),
|
||||
) {
|
||||
val grouped =
|
||||
posts.groupBy { it.createdAt.asZonedDateTime().month }.apply {
|
||||
if (sortOrder) {
|
||||
toSortedMap(
|
||||
Comparator { first, second ->
|
||||
return@Comparator if (first > second) -1 else if (first < second) 1 else 0
|
||||
}
|
||||
)
|
||||
}
|
||||
val grouped = posts.groupBy { it.createdAt.asZonedDateTime().month }.toMutableMap()
|
||||
if (reverseSort) {
|
||||
val copy = grouped.toMap()
|
||||
grouped.clear()
|
||||
copy.keys.reversed().forEach { month ->
|
||||
grouped[month] = requireNotNull(copy[month]).reversed()
|
||||
}
|
||||
}
|
||||
grouped.forEach { (month, posts) ->
|
||||
stickyHeader { MonthHeader(month = month) }
|
||||
@Suppress("NAME_SHADOWING") val posts = if (sortOrder) posts.reversed() else posts
|
||||
items(posts) { item ->
|
||||
LobstersItem(
|
||||
post = item,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue