Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Commit

Permalink
feat: navigation params (#55)
Browse files Browse the repository at this point in the history
* change branch

Signed-off-by: Arthur Bleil <[email protected]>

* change branch

Signed-off-by: Arthur Bleil <[email protected]>

* feat: Navigation Params

Signed-off-by: Arthur Bleil <[email protected]>

Signed-off-by: Arthur Bleil <[email protected]>
  • Loading branch information
arthurbleilzup authored Nov 10, 2022
1 parent e2a4ccc commit 51228f6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
10 changes: 8 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ android {
}
// TODO Extract the code below to another file
// ------------------------- Publication configuration --------------------- //

val releaseVersion = !version.toString().endsWith("-SNAPSHOT")
val sonatypeUsername = System.getenv("ORG_GRADLE_PROJECT_mavenCentralUsername") ?: ""
val sonatypePassword = System.getenv("ORG_GRADLE_PROJECT_mavenCentralPassword") ?: ""
val versionName = System.getenv("VERSION_NAME") ?: project.property("VERSION_NAME").toString()
Expand Down Expand Up @@ -178,7 +178,7 @@ publishing {
name="oss"
val releasesRepoUrl = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
val snapshotsRepoUrl = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
url = if (version.toString().endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl
url = if (releaseVersion) releasesRepoUrl else snapshotsRepoUrl
credentials {
username = sonatypeUsername
password = sonatypePassword
Expand Down Expand Up @@ -221,6 +221,12 @@ publishing {
}

signing {
setRequired {
// signing is required if this is a release version and the artifacts are to be published
// do not use hasTask() as this require realization of the tasks that maybe are not necessary
releaseVersion && gradle.taskGraph.allTasks.any { it is PublishToMavenRepository }
}
@Suppress("UnstableApiUsage")
sign(publishing.publications)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ data class ViewRequest(
* UI tree to show if an error occurs and the view can't be fetched.
*/
val fallback: Map<String, Any?>? = null,
/**
* The map of state ids and its values that will be used on the next page.
*/
val params: Map<String, Any?>? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,26 @@ import com.zup.nimbus.core.network.ServerDrivenHttpMethod
import com.zup.nimbus.core.network.ViewRequest
import com.zup.nimbus.core.ActionTriggeredEvent
import com.zup.nimbus.core.utils.UnexpectedDataTypeError
import com.zup.nimbus.core.utils.then
import com.zup.nimbus.core.utils.valueOfEnum
import com.zup.nimbus.core.utils.valueOfKey

private inline fun getNavigator(event: ActionEvent) = event.scope.view.navigator

private fun requestFromEvent(event: ActionEvent): ViewRequest {
private fun requestFromEvent(event: ActionEvent, isPushOrPresent: Boolean): ViewRequest {
val properties = event.action.properties
return ViewRequest(
url = valueOfKey(properties, "url"),
method = valueOfEnum(properties, "method", ServerDrivenHttpMethod.Get),
headers = valueOfKey(properties, "headers"),
fallback = valueOfKey(properties, "fallback"),
params = (isPushOrPresent then valueOfKey(properties, "params")),
)
}

private fun pushOrPresent(event: ActionTriggeredEvent, isPush: Boolean) {
try {
val request = requestFromEvent(event)
val request = requestFromEvent(event, true)
if (isPush) getNavigator(event).push(request)
else getNavigator(event).present(request)
} catch (e: UnexpectedDataTypeError) {
Expand Down Expand Up @@ -51,7 +53,7 @@ internal fun onPushOrPresentInitialized(event: ActionInitializedEvent) {
try {
val prefetch: Boolean = valueOfKey(event.action.properties, "prefetch") ?: false
if (!prefetch) return
val request = requestFromEvent(event)
val request = requestFromEvent(event, true)
event.scope.nimbus.viewClient.preFetch(request)
} catch (e: Throwable) {
event.scope.nimbus.logger.error("Error while pre-fetching view.\n${e.message}")
Expand Down

0 comments on commit 51228f6

Please sign in to comment.