mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-17 22:37:03 +05:30
Fix pagination
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
20a38c662e
commit
906cfb5e43
2 changed files with 2 additions and 6 deletions
|
@ -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)
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue