chore: migrate to data object

This commit is contained in:
Harsh Shandilya 2023-12-07 01:22:34 +05:30
parent 8e50cb3e77
commit 53f0656353
No known key found for this signature in database
4 changed files with 19 additions and 19 deletions

View file

@ -45,7 +45,7 @@ fun rememberPostActions(
viewModel.markPostAsRead(postId)
val currentRoute = navController.currentDestination?.route
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)
}

View file

@ -9,34 +9,34 @@ package dev.msfjarvis.claw.android.ui.navigation
sealed class Destinations {
abstract val route: String
object Hottest : Destinations() {
data object Hottest : Destinations() {
override val route = "hottest"
}
object Newest : Destinations() {
data object Newest : Destinations() {
override val route = "newest"
}
object Saved : Destinations() {
data object Saved : Destinations() {
override val route = "saved"
}
object Comments : Destinations() {
const val placeholder = "{postId}"
override val route = "comments/$placeholder"
data object Comments : Destinations() {
const val PLACEHOLDER = "{postId}"
override val route = "comments/$PLACEHOLDER"
}
object User : Destinations() {
const val placeholder = "{username}"
override val route = "user/$placeholder"
data object User : Destinations() {
const val PLACEHOLDER = "{username}"
override val route = "user/$PLACEHOLDER"
}
object DataTransfer : Destinations() {
override val route: String = "datatransfer"
data object DataTransfer : Destinations() {
override val route = "datatransfer"
}
object Search : Destinations() {
override val route: String = "search"
data object Search : Destinations() {
override val route = "search"
}
companion object {

View file

@ -120,7 +120,7 @@ fun LobstersPostsScreen(
LaunchedEffect(false) {
if (postIdOverride != null) {
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 }),
deepLinks =
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 ->
val postId =
@ -305,7 +305,7 @@ fun LobstersPostsScreen(
route = Destinations.User.route,
arguments = listOf(navArgument("username") { type = NavType.StringType }),
deepLinks =
listOf(navDeepLink { uriPattern = "$uri/u/${Destinations.User.placeholder}" }),
listOf(navDeepLink { uriPattern = "$uri/u/${Destinations.User.PLACEHOLDER}" }),
) { backStackEntry ->
val username =
requireNotNull(backStackEntry.arguments?.getString("username")) {

View file

@ -11,5 +11,5 @@ internal sealed class NetworkState {
class Error(val error: Throwable, val description: String) : NetworkState()
object Loading : NetworkState()
data object Loading : NetworkState()
}