diff options
5 files changed, 25 insertions, 27 deletions
diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/Application.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/Application.kt index 385abb18..fcc9e863 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/Application.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/Application.kt @@ -5,17 +5,17 @@ import org.luxons.sevenwonders.ui.components.game.gameScene import org.luxons.sevenwonders.ui.components.gameBrowser.gameBrowser import org.luxons.sevenwonders.ui.components.home.home import org.luxons.sevenwonders.ui.components.lobby.lobby -import org.luxons.sevenwonders.ui.router.Route +import org.luxons.sevenwonders.ui.router.SwRoute import react.RBuilder import react.router.dom.* fun RBuilder.application() = HashRouter { errorDialog() Switch { - route(Route.GAME_BROWSER.path) { gameBrowser() } - route(Route.GAME.path) { gameScene() } - route(Route.LOBBY.path) { lobby() } - route(Route.HOME.path, exact = true) { home() } + route(SwRoute.GAME_BROWSER.path) { gameBrowser() } + route(SwRoute.GAME.path) { gameScene() } + route(SwRoute.LOBBY.path) { lobby() } + route(SwRoute.HOME.path) { home() } Redirect { attrs { from = "*" diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/errors/ErrorDialog.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/errors/ErrorDialog.kt index a332c565..68b23ce0 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/errors/ErrorDialog.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/components/errors/ErrorDialog.kt @@ -8,7 +8,7 @@ import blueprintjs.icons.IconNames import kotlinx.browser.window import org.luxons.sevenwonders.ui.redux.* import org.luxons.sevenwonders.ui.router.Navigate -import org.luxons.sevenwonders.ui.router.Route +import org.luxons.sevenwonders.ui.router.SwRoute import react.* import react.dom.p import styled.css @@ -56,7 +56,7 @@ class ErrorDialogPresenter(props: ErrorDialogProps) : RComponent<ErrorDialogProp private fun goHomeAndRefresh() { // we don't use a redux action here because we actually want to redirect and refresh the page - window.location.href = Route.HOME.path + window.location.href = SwRoute.HOME.path } fun RBuilder.errorDialog() = errorDialog {} @@ -67,6 +67,6 @@ private val errorDialog = connectStateAndDispatch<ErrorDialogStateProps, ErrorDi errorMessage = state.fatalError }, mapDispatchToProps = { dispatch, _ -> - goHome = { dispatch(Navigate(Route.HOME)) } + goHome = { dispatch(Navigate(SwRoute.HOME)) } }, ) diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/RouteBasedSagas.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/RouteBasedSagas.kt index fee5a960..3343e62e 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/RouteBasedSagas.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/RouteBasedSagas.kt @@ -1,11 +1,10 @@ package org.luxons.sevenwonders.ui.redux.sagas -import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.map import org.luxons.sevenwonders.client.SevenWondersSession import org.luxons.sevenwonders.ui.redux.* import org.luxons.sevenwonders.ui.router.Navigate -import org.luxons.sevenwonders.ui.router.Route +import org.luxons.sevenwonders.ui.router.SwRoute suspend fun SwSagaContext.gameBrowserSaga(session: SevenWondersSession) { // browser navigation could have brought us here: we should leave the game/lobby @@ -31,7 +30,7 @@ suspend fun SwSagaContext.lobbySaga(session: SevenWondersSession) { session.leaveGame() } else if (reduxState.currentLobby == null) { console.warn("User went to lobby page via browser navigation, redirecting to game browser...") - dispatch(Navigate(Route.GAME_BROWSER)) + dispatch(Navigate(SwRoute.GAME_BROWSER)) } } diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/Sagas.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/Sagas.kt index ba3949cc..08e5f3d9 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/Sagas.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/Sagas.kt @@ -2,7 +2,6 @@ package org.luxons.sevenwonders.ui.redux.sagas import kotlinx.browser.window import kotlinx.coroutines.* -import kotlinx.coroutines.flow.collect import org.hildan.krossbow.stomp.ConnectionException import org.hildan.krossbow.stomp.MissingHeartBeatException import org.hildan.krossbow.stomp.WebSocketClosedUnexpectedly @@ -10,7 +9,7 @@ import org.luxons.sevenwonders.client.* import org.luxons.sevenwonders.model.api.events.GameEvent import org.luxons.sevenwonders.ui.redux.* import org.luxons.sevenwonders.ui.router.Navigate -import org.luxons.sevenwonders.ui.router.Route +import org.luxons.sevenwonders.ui.router.SwRoute import org.luxons.sevenwonders.ui.router.routerSaga import redux.RAction import redux.WrapperAction @@ -37,12 +36,12 @@ suspend fun SwSagaContext.rootSaga() = try { val player = session.chooseNameAndAwait(action.playerName) dispatch(SetCurrentPlayerAction(player)) - routerSaga(Route.GAME_BROWSER) { + routerSaga(SwRoute.GAME_BROWSER) { when (it) { - Route.HOME -> Unit - Route.LOBBY -> lobbySaga(session) - Route.GAME_BROWSER -> gameBrowserSaga(session) - Route.GAME -> gameSaga(session) + SwRoute.HOME -> Unit + SwRoute.LOBBY -> lobbySaga(session) + SwRoute.GAME_BROWSER -> gameBrowserSaga(session) + SwRoute.GAME -> gameSaga(session) } } } @@ -102,23 +101,23 @@ private fun SwSagaContext.launchApiEventHandlersIn(scope: CoroutineScope, sessio when (event) { is GameEvent.NameChosen -> { dispatch(SetCurrentPlayerAction(event.player)) - dispatch(Navigate(Route.GAME_BROWSER)) + dispatch(Navigate(SwRoute.GAME_BROWSER)) } is GameEvent.LobbyJoined -> { dispatch(EnterLobbyAction(event.lobby)) - dispatch(Navigate(Route.LOBBY)) + dispatch(Navigate(SwRoute.LOBBY)) } is GameEvent.LobbyUpdated -> { dispatch(UpdateLobbyAction(event.lobby)) } GameEvent.LobbyLeft -> { dispatch(LeaveLobbyAction) - dispatch(Navigate(Route.GAME_BROWSER)) + dispatch(Navigate(SwRoute.GAME_BROWSER)) } is GameEvent.GameStarted -> { val currentLobby = reduxState.currentLobby ?: error("Received game started event without being in a lobby") dispatch(EnterGameAction(currentLobby, event.turnInfo)) - dispatch(Navigate(Route.GAME)) + dispatch(Navigate(SwRoute.GAME)) } is GameEvent.NewTurnStarted -> dispatch(TurnInfoEvent(event.turnInfo)) is GameEvent.MovePrepared -> dispatch(PreparedMoveEvent(event.move)) diff --git a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/router/Router.kt b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/router/Router.kt index 00f8cda5..1a0840cf 100644 --- a/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/router/Router.kt +++ b/sw-ui/src/main/kotlin/org/luxons/sevenwonders/ui/router/Router.kt @@ -7,7 +7,7 @@ import kotlinx.coroutines.launch import org.luxons.sevenwonders.ui.redux.sagas.SwSagaContext import redux.RAction -enum class Route(val path: String) { +enum class SwRoute(val path: String) { HOME("/"), GAME_BROWSER("/games"), LOBBY("/lobby"), @@ -20,18 +20,18 @@ enum class Route(val path: String) { } } -data class Navigate(val route: Route) : RAction +data class Navigate(val route: SwRoute) : RAction suspend fun SwSagaContext.routerSaga( - startRoute: Route, - runRouteSaga: suspend SwSagaContext.(Route) -> Unit, + startRoute: SwRoute, + runRouteSaga: suspend SwSagaContext.(SwRoute) -> Unit, ) { coroutineScope { window.location.hash = startRoute.path launch { changeRouteOnNavigateAction() } var currentSaga: Job = launch { runRouteSaga(startRoute) } window.onhashchange = { event -> - val route = Route.from(event.newURL.substringAfter("#")) + val route = SwRoute.from(event.newURL.substringAfter("#")) currentSaga.cancel() currentSaga = this@coroutineScope.launch { runRouteSaga(route) |