diff options
author | Joffrey Bion <joffrey.bion@booking.com> | 2020-03-26 15:12:32 +0100 |
---|---|---|
committer | Joffrey Bion <joffrey.bion@booking.com> | 2020-03-27 10:59:39 +0100 |
commit | fee376b1136fa35d3804d63a7c5b276154eb5c6b (patch) | |
tree | 2d622cf28562e0bcdbd697b2cc0998110e54cb07 | |
parent | Properly unsubscribe from server in GameBrowser sagas (diff) | |
download | seven-wonders-fee376b1136fa35d3804d63a7c5b276154eb5c6b.tar.gz seven-wonders-fee376b1136fa35d3804d63a7c5b276154eb5c6b.tar.bz2 seven-wonders-fee376b1136fa35d3804d63a7c5b276154eb5c6b.zip |
Remove gameId parameter for the game scene route
5 files changed, 15 insertions, 13 deletions
diff --git a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/Application.kt b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/Application.kt index 5e602ae5..d692c256 100644 --- a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/Application.kt +++ b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/Application.kt @@ -19,8 +19,8 @@ interface IdProps : RProps { fun RBuilder.application() = hashRouter { switch { route("/games") { gameBrowser() } - route<IdProps>("/game/:id") { props -> gameScene(props.match.params.id) } - route<IdProps>("/lobby") { lobby() } + route("/game") { gameScene() } + route("/lobby") { lobby() } route("/", exact = true) { home() } redirect(from = "*", to = "/") } diff --git a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/GameScene.kt b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/GameScene.kt index 44136993..d8b5ec7d 100644 --- a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/GameScene.kt +++ b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/GameScene.kt @@ -3,6 +3,6 @@ package org.luxons.sevenwonders.ui.components.game import react.RBuilder import react.dom.* -fun RBuilder.gameScene(gameId: Long) = div { - h1 { +"Game $gameId" } +fun RBuilder.gameScene() = div { + h1 { +"Game" } } diff --git a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/GameSagas.kt b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/GameSagas.kt index 29242782..eb4e3c13 100644 --- a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/GameSagas.kt +++ b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/GameSagas.kt @@ -3,13 +3,15 @@ package org.luxons.sevenwonders.ui.redux.sagas import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.launch import org.luxons.sevenwonders.client.SevenWondersSession -import org.luxons.sevenwonders.ui.redux.SwState -import redux.RAction -import redux.WrapperAction +import org.luxons.sevenwonders.model.api.State -suspend fun SwSagaContext.gameSaga(session: SevenWondersSession, gameId: Long) { +suspend fun SwSagaContext.gameSaga(session: SevenWondersSession) { + val lobby = getState().currentLobby ?: error("Game saga run without a current game") + if (lobby.state != State.PLAYING) { + error("Game saga run but the game hasn't started") + } coroutineScope { - launch { watchPlayerReady(session, gameId) } + launch { watchPlayerReady(session, lobby.id) } } } diff --git a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/LobbySagas.kt b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/LobbySagas.kt index bf13c47e..b2d83416 100644 --- a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/LobbySagas.kt +++ b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/LobbySagas.kt @@ -29,8 +29,8 @@ private suspend fun SwSagaContext.handleGameStart(session: SevenWondersSession, dispatch(EnterGameAction(lobbyId)) coroutineScope { - launch { gameSaga(session, lobbyId) } - Router.game(lobbyId) + launch { gameSaga(session) } + Router.game() } } diff --git a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/router/Router.kt b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/router/Router.kt index 25cb2ec1..09789ee1 100644 --- a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/router/Router.kt +++ b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/router/Router.kt @@ -8,8 +8,8 @@ object Router { push("/games") } - fun game(id: Long) { - push("/game/$id") + fun game() { + push("/game") } fun lobby() { |