Fix pagination

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya 2020-10-29 16:22:10 +05:30
parent 20a38c662e
commit 906cfb5e43
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80
2 changed files with 2 additions and 6 deletions

View file

@ -10,7 +10,6 @@ import androidx.compose.material.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Providers
import androidx.compose.runtime.ambientOf
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.platform.setContent
import androidx.navigation.compose.KEY_ROUTE
@ -53,8 +52,6 @@ fun LobstersApp(
viewModel: LobstersViewModel
) {
val urlLauncher = UrlLauncherAmbient.current
val posts = viewModel.posts.collectAsState()
val lastIndex = posts.value.lastIndex
val navController = rememberNavController()
val destinations = arrayOf(Destination.Hottest, Destination.Saved)
@ -92,7 +89,7 @@ fun LobstersApp(
) {
NavHost(navController, startDestination = Destination.Hottest.route) {
composable(Destination.Hottest.route) {
HottestPosts(lastIndex = lastIndex, urlLauncher = urlLauncher , viewModel = viewModel)
HottestPosts(urlLauncher = urlLauncher, viewModel = viewModel)
}
composable(Destination.Saved.route) {
SavedPosts(urlLauncher = urlLauncher, viewModel = viewModel)

View file

@ -13,7 +13,6 @@ import dev.msfjarvis.lobsters.urllauncher.UrlLauncher
@Composable
fun HottestPosts(
lastIndex: Int,
urlLauncher: UrlLauncher,
viewModel: LobstersViewModel,
) {
@ -28,7 +27,7 @@ fun HottestPosts(
state = listState,
modifier = Modifier.padding(horizontal = 8.dp)
) { index, item ->
if (lastIndex == index) {
if (posts.lastIndex == index) {
viewModel.getMorePosts()
}
LobstersItem(