Skip to content

Commit

Permalink
Added a toQueryString() for creating links.
Browse files Browse the repository at this point in the history
  • Loading branch information
handstandsam committed Jan 24, 2025
1 parent 7f45498 commit 4f82453
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,24 @@ import com.squareup.invert.common.navigation.NavPageId
import com.squareup.invert.common.navigation.NavRoute

abstract class BaseNavRoute(
final override val navPage: NavPage,
final override val navPage: NavPage,
) : NavRoute {
override fun toSearchParams(): Map<String, String> = toParamsWithOnlyPageId(this)
override fun toSearchParams(): Map<String, String> = toParamsWithOnlyPageId(this)

override val page: NavPageId = navPage.pageId
override val page: NavPageId = navPage.pageId

companion object {
companion object {

const val PAGE_ID_PARAM = "page"
const val PAGE_ID_PARAM = "page"

fun toParamsWithOnlyPageId(navRoute: NavRoute): MutableMap<String, String> {
return mutableMapOf<String, String>().apply {
this[PAGE_ID_PARAM] = navRoute.page
}
}
fun toParamsWithOnlyPageId(navRoute: NavRoute): MutableMap<String, String> {
return mutableMapOf<String, String>().apply {
this[PAGE_ID_PARAM] = navRoute.page
}
}
}

fun toQueryString(): String {
return toSearchParams().map { (key, value) -> "$key=$value" }.joinToString("&")
}
}

0 comments on commit 4f82453

Please sign in to comment.