mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-15 02:57:04 +05:30
refactor: fix search destination
This commit is contained in:
parent
bf0a6c40e8
commit
92fb2939e6
3 changed files with 21 additions and 69 deletions
|
@ -10,15 +10,11 @@ import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.PaddingValues
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.systemBarsPadding
|
|
||||||
import androidx.compose.foundation.lazy.LazyListState
|
import androidx.compose.foundation.lazy.LazyListState
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.testTag
|
import androidx.compose.ui.platform.testTag
|
||||||
import androidx.compose.ui.semantics.isTraversalGroup
|
|
||||||
import androidx.compose.ui.semantics.semantics
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.zIndex
|
|
||||||
import androidx.paging.compose.LazyPagingItems
|
import androidx.paging.compose.LazyPagingItems
|
||||||
import dev.msfjarvis.claw.common.posts.PostActions
|
import dev.msfjarvis.claw.common.posts.PostActions
|
||||||
import dev.msfjarvis.claw.common.ui.SearchBar
|
import dev.msfjarvis.claw.common.ui.SearchBar
|
||||||
|
@ -38,10 +34,7 @@ fun SearchList(
|
||||||
setSearchQuery(query)
|
setSearchQuery(query)
|
||||||
lazyPagingItems.refresh()
|
lazyPagingItems.refresh()
|
||||||
}
|
}
|
||||||
Column(
|
Column(modifier.padding(contentPadding).fillMaxWidth()) {
|
||||||
modifier =
|
|
||||||
modifier.systemBarsPadding().semantics { isTraversalGroup = true }.zIndex(1f).fillMaxWidth()
|
|
||||||
) {
|
|
||||||
SearchBar(
|
SearchBar(
|
||||||
value = searchQuery,
|
value = searchQuery,
|
||||||
onValueChange = setSearchQuery,
|
onValueChange = setSearchQuery,
|
||||||
|
@ -52,7 +45,7 @@ fun SearchList(
|
||||||
lazyPagingItems = lazyPagingItems,
|
lazyPagingItems = lazyPagingItems,
|
||||||
listState = listState,
|
listState = listState,
|
||||||
postActions = postActions,
|
postActions = postActions,
|
||||||
contentPadding = contentPadding,
|
contentPadding = PaddingValues(0.dp),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -246,7 +246,12 @@ fun Nav3Screen(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
entry<Search> {
|
entry<Search> {
|
||||||
SearchScreen(urlLauncher = urlLauncher, setWebUri = setWebUri, viewModel = viewModel)
|
setWebUri("https://lobste.rs/search")
|
||||||
|
SearchScreen(
|
||||||
|
viewModel = viewModel,
|
||||||
|
postActions = postActions,
|
||||||
|
contentPadding = contentPadding,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
entry<AboutLibraries> {
|
entry<AboutLibraries> {
|
||||||
LibrariesContainer(contentPadding = contentPadding, modifier = Modifier.fillMaxSize())
|
LibrariesContainer(contentPadding = contentPadding, modifier = Modifier.fillMaxSize())
|
||||||
|
|
|
@ -6,78 +6,32 @@
|
||||||
*/
|
*/
|
||||||
package dev.msfjarvis.claw.android.ui.screens
|
package dev.msfjarvis.claw.android.ui.screens
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
import androidx.compose.material3.Scaffold
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import androidx.navigation.compose.NavHost
|
|
||||||
import androidx.navigation.compose.composable
|
|
||||||
import androidx.navigation.compose.rememberNavController
|
|
||||||
import androidx.navigation.toRoute
|
|
||||||
import androidx.paging.compose.collectAsLazyPagingItems
|
import androidx.paging.compose.collectAsLazyPagingItems
|
||||||
import com.deliveryhero.whetstone.compose.injectedViewModel
|
import com.deliveryhero.whetstone.compose.injectedViewModel
|
||||||
import dev.msfjarvis.claw.android.ui.PostActions
|
|
||||||
import dev.msfjarvis.claw.android.ui.lists.SearchList
|
import dev.msfjarvis.claw.android.ui.lists.SearchList
|
||||||
import dev.msfjarvis.claw.android.ui.navigation.Comments
|
|
||||||
import dev.msfjarvis.claw.android.ui.navigation.Search
|
|
||||||
import dev.msfjarvis.claw.android.ui.navigation.User
|
|
||||||
import dev.msfjarvis.claw.android.viewmodel.ClawViewModel
|
import dev.msfjarvis.claw.android.viewmodel.ClawViewModel
|
||||||
import dev.msfjarvis.claw.common.comments.CommentsPage
|
import dev.msfjarvis.claw.common.posts.PostActions
|
||||||
import dev.msfjarvis.claw.common.urllauncher.UrlLauncher
|
|
||||||
import dev.msfjarvis.claw.common.user.UserProfile
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun SearchScreen(
|
fun SearchScreen(
|
||||||
urlLauncher: UrlLauncher,
|
postActions: PostActions,
|
||||||
setWebUri: (String?) -> Unit,
|
contentPadding: PaddingValues,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
viewModel: ClawViewModel = injectedViewModel(),
|
viewModel: ClawViewModel = injectedViewModel(),
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
|
||||||
val navController = rememberNavController()
|
|
||||||
val postActions = remember {
|
|
||||||
PostActions(context, urlLauncher, viewModel) { navController.navigate(Comments(it)) }
|
|
||||||
}
|
|
||||||
val listState = rememberLazyListState()
|
val listState = rememberLazyListState()
|
||||||
val searchResults = viewModel.searchResults.collectAsLazyPagingItems()
|
val searchResults = viewModel.searchResults.collectAsLazyPagingItems()
|
||||||
|
SearchList(
|
||||||
Scaffold(modifier = modifier) { contentPadding ->
|
lazyPagingItems = searchResults,
|
||||||
NavHost(navController = navController, startDestination = Search) {
|
listState = listState,
|
||||||
composable<Search> {
|
postActions = postActions,
|
||||||
setWebUri("https://lobste.rs/search")
|
searchQuery = viewModel.searchQuery,
|
||||||
SearchList(
|
contentPadding = contentPadding,
|
||||||
lazyPagingItems = searchResults,
|
setSearchQuery = { query -> viewModel.searchQuery = query },
|
||||||
listState = listState,
|
modifier = modifier,
|
||||||
postActions = postActions,
|
)
|
||||||
searchQuery = viewModel.searchQuery,
|
|
||||||
contentPadding = contentPadding,
|
|
||||||
setSearchQuery = { query -> viewModel.searchQuery = query },
|
|
||||||
)
|
|
||||||
}
|
|
||||||
composable<Comments> { backStackEntry ->
|
|
||||||
val postId = backStackEntry.toRoute<Comments>().postId
|
|
||||||
setWebUri("https://lobste.rs/s/$postId")
|
|
||||||
CommentsPage(
|
|
||||||
postId = postId,
|
|
||||||
postActions = postActions,
|
|
||||||
getSeenComments = viewModel::getSeenComments,
|
|
||||||
markSeenComments = viewModel::markSeenComments,
|
|
||||||
contentPadding = contentPadding,
|
|
||||||
openUserProfile = { navController.navigate(User(it)) },
|
|
||||||
)
|
|
||||||
}
|
|
||||||
composable<User> { backStackEntry ->
|
|
||||||
val username = backStackEntry.toRoute<User>().username
|
|
||||||
setWebUri("https://lobste.rs/u/$username")
|
|
||||||
UserProfile(
|
|
||||||
username = username,
|
|
||||||
getProfile = viewModel::getUserProfile,
|
|
||||||
openUserProfile = { navController.navigate(User(it)) },
|
|
||||||
contentPadding = contentPadding,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue