mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 17:37:05 +05:30
chore: migrate to data object
This commit is contained in:
parent
8e50cb3e77
commit
53f0656353
4 changed files with 19 additions and 19 deletions
|
@ -45,7 +45,7 @@ fun rememberPostActions(
|
||||||
viewModel.markPostAsRead(postId)
|
viewModel.markPostAsRead(postId)
|
||||||
val currentRoute = navController.currentDestination?.route
|
val currentRoute = navController.currentDestination?.route
|
||||||
val newRoute =
|
val newRoute =
|
||||||
Destinations.Comments.route.replace(Destinations.Comments.placeholder, postId)
|
Destinations.Comments.route.replace(Destinations.Comments.PLACEHOLDER, postId)
|
||||||
if (currentRoute != Destinations.Comments.route) navController.navigate(newRoute)
|
if (currentRoute != Destinations.Comments.route) navController.navigate(newRoute)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,34 +9,34 @@ package dev.msfjarvis.claw.android.ui.navigation
|
||||||
sealed class Destinations {
|
sealed class Destinations {
|
||||||
abstract val route: String
|
abstract val route: String
|
||||||
|
|
||||||
object Hottest : Destinations() {
|
data object Hottest : Destinations() {
|
||||||
override val route = "hottest"
|
override val route = "hottest"
|
||||||
}
|
}
|
||||||
|
|
||||||
object Newest : Destinations() {
|
data object Newest : Destinations() {
|
||||||
override val route = "newest"
|
override val route = "newest"
|
||||||
}
|
}
|
||||||
|
|
||||||
object Saved : Destinations() {
|
data object Saved : Destinations() {
|
||||||
override val route = "saved"
|
override val route = "saved"
|
||||||
}
|
}
|
||||||
|
|
||||||
object Comments : Destinations() {
|
data object Comments : Destinations() {
|
||||||
const val placeholder = "{postId}"
|
const val PLACEHOLDER = "{postId}"
|
||||||
override val route = "comments/$placeholder"
|
override val route = "comments/$PLACEHOLDER"
|
||||||
}
|
}
|
||||||
|
|
||||||
object User : Destinations() {
|
data object User : Destinations() {
|
||||||
const val placeholder = "{username}"
|
const val PLACEHOLDER = "{username}"
|
||||||
override val route = "user/$placeholder"
|
override val route = "user/$PLACEHOLDER"
|
||||||
}
|
}
|
||||||
|
|
||||||
object DataTransfer : Destinations() {
|
data object DataTransfer : Destinations() {
|
||||||
override val route: String = "datatransfer"
|
override val route = "datatransfer"
|
||||||
}
|
}
|
||||||
|
|
||||||
object Search : Destinations() {
|
data object Search : Destinations() {
|
||||||
override val route: String = "search"
|
override val route = "search"
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
|
@ -120,7 +120,7 @@ fun LobstersPostsScreen(
|
||||||
LaunchedEffect(false) {
|
LaunchedEffect(false) {
|
||||||
if (postIdOverride != null) {
|
if (postIdOverride != null) {
|
||||||
navController.navigate(
|
navController.navigate(
|
||||||
Destinations.Comments.route.replace(Destinations.Comments.placeholder, postIdOverride)
|
Destinations.Comments.route.replace(Destinations.Comments.PLACEHOLDER, postIdOverride)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -284,8 +284,8 @@ fun LobstersPostsScreen(
|
||||||
arguments = listOf(navArgument("postId") { type = NavType.StringType }),
|
arguments = listOf(navArgument("postId") { type = NavType.StringType }),
|
||||||
deepLinks =
|
deepLinks =
|
||||||
listOf(
|
listOf(
|
||||||
navDeepLink { uriPattern = "$uri/s/${Destinations.Comments.placeholder}/.*" },
|
navDeepLink { uriPattern = "$uri/s/${Destinations.Comments.PLACEHOLDER}/.*" },
|
||||||
navDeepLink { uriPattern = "$uri/s/${Destinations.Comments.placeholder}" },
|
navDeepLink { uriPattern = "$uri/s/${Destinations.Comments.PLACEHOLDER}" },
|
||||||
),
|
),
|
||||||
) { backStackEntry ->
|
) { backStackEntry ->
|
||||||
val postId =
|
val postId =
|
||||||
|
@ -305,7 +305,7 @@ fun LobstersPostsScreen(
|
||||||
route = Destinations.User.route,
|
route = Destinations.User.route,
|
||||||
arguments = listOf(navArgument("username") { type = NavType.StringType }),
|
arguments = listOf(navArgument("username") { type = NavType.StringType }),
|
||||||
deepLinks =
|
deepLinks =
|
||||||
listOf(navDeepLink { uriPattern = "$uri/u/${Destinations.User.placeholder}" }),
|
listOf(navDeepLink { uriPattern = "$uri/u/${Destinations.User.PLACEHOLDER}" }),
|
||||||
) { backStackEntry ->
|
) { backStackEntry ->
|
||||||
val username =
|
val username =
|
||||||
requireNotNull(backStackEntry.arguments?.getString("username")) {
|
requireNotNull(backStackEntry.arguments?.getString("username")) {
|
||||||
|
|
|
@ -11,5 +11,5 @@ internal sealed class NetworkState {
|
||||||
|
|
||||||
class Error(val error: Throwable, val description: String) : NetworkState()
|
class Error(val error: Throwable, val description: String) : NetworkState()
|
||||||
|
|
||||||
object Loading : NetworkState()
|
data object Loading : NetworkState()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue