android: add comments destination

This commit is contained in:
Harsh Shandilya 2021-10-04 16:56:21 +05:30
parent e85e25aa50
commit 7f54e6ff1b
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80
3 changed files with 12 additions and 1 deletions

View file

@ -24,6 +24,7 @@ fun HottestPosts(
toggleSave: suspend (SavedPost) -> Unit, toggleSave: suspend (SavedPost) -> Unit,
reloadPosts: () -> Unit, reloadPosts: () -> Unit,
launchUrl: (String) -> Unit, launchUrl: (String) -> Unit,
viewComments: (String) -> Unit,
modifier: Modifier, modifier: Modifier,
) { ) {
val coroutineScope = rememberCoroutineScope() val coroutineScope = rememberCoroutineScope()
@ -40,6 +41,7 @@ fun HottestPosts(
launchUrl = launchUrl, launchUrl = launchUrl,
listState = listState, listState = listState,
isSaved = isPostSaved, isSaved = isPostSaved,
viewComments = viewComments,
toggleSave = { coroutineScope.launch { toggleSave(it) } }, toggleSave = { coroutineScope.launch { toggleSave(it) } },
modifier = Modifier.padding(top = 16.dp).then(modifier), modifier = Modifier.padding(top = 16.dp).then(modifier),
) )

View file

@ -28,6 +28,7 @@ import com.google.accompanist.insets.ProvideWindowInsets
import com.google.accompanist.insets.navigationBarsPadding import com.google.accompanist.insets.navigationBarsPadding
import com.google.accompanist.insets.statusBarsPadding import com.google.accompanist.insets.statusBarsPadding
import com.google.accompanist.systemuicontroller.rememberSystemUiController import com.google.accompanist.systemuicontroller.rememberSystemUiController
import dev.msfjarvis.claw.android.comments.CommentsPage
import dev.msfjarvis.claw.android.viewmodel.ClawViewModel import dev.msfjarvis.claw.android.viewmodel.ClawViewModel
import dev.msfjarvis.claw.common.theme.LobstersTheme import dev.msfjarvis.claw.common.theme.LobstersTheme
import dev.msfjarvis.claw.common.urllauncher.UrlLauncher import dev.msfjarvis.claw.common.urllauncher.UrlLauncher
@ -92,9 +93,16 @@ fun LobstersApp(
viewModel::toggleSave, viewModel::toggleSave,
viewModel::reloadPosts, viewModel::reloadPosts,
urlLauncher::launch, urlLauncher::launch,
{ navController.navigate("comments/$it") },
Modifier.nestedScroll(nestedScrollConnection), Modifier.nestedScroll(nestedScrollConnection),
) )
} }
composable("comments/{postId}") { backStackEntry ->
CommentsPage(
postId = requireNotNull(backStackEntry.arguments?.getString("postId")),
getDetails = viewModel::getPostComments,
)
}
} }
} }
} }

View file

@ -26,6 +26,7 @@ fun NetworkPosts(
launchUrl: (String) -> Unit, launchUrl: (String) -> Unit,
isSaved: suspend (SavedPost) -> Boolean, isSaved: suspend (SavedPost) -> Boolean,
toggleSave: (SavedPost) -> Unit, toggleSave: (SavedPost) -> Unit,
viewComments: (String) -> Unit,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
) { ) {
val coroutineScope = rememberCoroutineScope() val coroutineScope = rememberCoroutineScope()
@ -42,7 +43,7 @@ fun NetworkPosts(
post = dbModel, post = dbModel,
isSaved = saved, isSaved = saved,
viewPost = { launchUrl(item.url.ifEmpty { item.commentsUrl }) }, viewPost = { launchUrl(item.url.ifEmpty { item.commentsUrl }) },
viewComments = { launchUrl(item.commentsUrl) }, viewComments = { viewComments(item.shortId) },
toggleSave = { toggleSave(dbModel) }, toggleSave = { toggleSave(dbModel) },
modifier = Modifier.padding(bottom = 16.dp, start = 16.dp, end = 16.dp), modifier = Modifier.padding(bottom = 16.dp, start = 16.dp, end = 16.dp),
) )