183: Sort saved posts months as well r=msfjarvis a=msfjarvis

bors r+

Co-authored-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
bors[bot] 2021-04-02 10:19:50 +00:00 committed by GitHub
commit d48d1c44ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -56,7 +56,16 @@ fun SavedPosts(
state = listState,
modifier = Modifier.then(modifier),
) {
val grouped = posts.groupBy { it.createdAt.asZonedDateTime().month }
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
}
)
}
}
grouped.forEach { (month, posts) ->
stickyHeader { MonthHeader(month = month) }
@Suppress("NAME_SHADOWING") val posts = if (sortOrder) posts.reversed() else posts