fix: comment navigation if empty (#865)

This commit is contained in:
Diego Beraldin 2024-05-18 13:42:59 +02:00 committed by GitHub
parent e434f49d6a
commit 8c9ff8e4d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -873,7 +873,7 @@ class PostDetailViewModel(
}
private fun navigateToPreviousComment(index: Int) {
val comments = uiState.value.comments
val comments = uiState.value.comments.takeIf { it.isNotEmpty() } ?: return
val (start, end) = 0 to index.coerceAtMost(comments.lastIndex)
val newIndex =
comments.subList(
@ -890,7 +890,7 @@ class PostDetailViewModel(
}
private fun navigateToNextComment(index: Int) {
val comments = uiState.value.comments
val comments = uiState.value.comments.takeIf { it.isNotEmpty() } ?: return
val (start, end) = (index + 1).coerceAtMost(comments.lastIndex) to comments.lastIndex
val newIndex =
comments.subList(