summaryrefslogtreecommitdiff
path: root/sw-ui-kt/src
diff options
context:
space:
mode:
Diffstat (limited to 'sw-ui-kt/src')
-rw-r--r--sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/Application.kt9
-rw-r--r--sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Game.kt4
-rw-r--r--sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/lobby/Lobby.kt4
-rw-r--r--sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/GameBrowserSagas.kt3
-rw-r--r--sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/LobbySagas.kt4
-rw-r--r--sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/Sagas.kt3
-rw-r--r--sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/router/Router.kt22
7 files changed, 39 insertions, 10 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 9a3a3e03..68ec1409 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
@@ -10,12 +10,17 @@ import react.router.dom.switch
import org.luxons.sevenwonders.ui.components.home.home
import org.luxons.sevenwonders.ui.components.lobby.lobby
+import react.RProps
+
+interface IdProps : RProps {
+ val id: Long
+}
fun RBuilder.application() = hashRouter {
switch {
- route("/game") { gameScene() }
route("/games") { gameBrowser() }
- route("/lobby") { lobby() }
+ route<IdProps>("/game/:id") { props -> gameScene(props.match.params.id) }
+ route<IdProps>("/lobby/:id") { props -> lobby(props.match.params.id) }
route("/", exact = true) { home() }
redirect(from = "*", to = "/")
}
diff --git a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Game.kt b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Game.kt
index d8b5ec7d..44136993 100644
--- a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Game.kt
+++ b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/game/Game.kt
@@ -3,6 +3,6 @@ package org.luxons.sevenwonders.ui.components.game
import react.RBuilder
import react.dom.*
-fun RBuilder.gameScene() = div {
- h1 { +"Game" }
+fun RBuilder.gameScene(gameId: Long) = div {
+ h1 { +"Game $gameId" }
}
diff --git a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/lobby/Lobby.kt b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/lobby/Lobby.kt
index 24d4da44..9804f954 100644
--- a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/lobby/Lobby.kt
+++ b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/components/lobby/Lobby.kt
@@ -3,9 +3,9 @@ package org.luxons.sevenwonders.ui.components.lobby
import react.RBuilder
import react.dom.*
-fun RBuilder.lobby() = div {
+fun RBuilder.lobby(lobbyId: Long) = div {
h1 {
- +"Lobby"
+ +"Lobby $lobbyId"
}
p {
+"Can't wait to play!"
diff --git a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/GameBrowserSagas.kt b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/GameBrowserSagas.kt
index b4c99827..02c8f5f0 100644
--- a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/GameBrowserSagas.kt
+++ b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/GameBrowserSagas.kt
@@ -10,6 +10,7 @@ import org.luxons.sevenwonders.ui.redux.RequestCreateGameAction
import org.luxons.sevenwonders.ui.redux.RequestJoinGameAction
import org.luxons.sevenwonders.ui.redux.UpdateGameListAction
import org.luxons.sevenwonders.ui.redux.UpdateLobbyAction
+import org.luxons.sevenwonders.ui.router.Router
import kotlin.coroutines.coroutineContext
suspend fun SwSagaContext.gameBrowserSaga(session: SevenWondersSession) {
@@ -51,6 +52,6 @@ private suspend fun SwSagaContext.handleGameJoined(
dispatch(EnterLobbyAction(lobby.id))
coroutineScope {
launch { lobbySaga(session, lobby.id) }
- // TODO push /lobby/{lobby.id}
+ Router.lobby(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 a58aeaa9..bf13c47e 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
@@ -6,6 +6,7 @@ import org.luxons.sevenwonders.client.SevenWondersSession
import org.luxons.sevenwonders.ui.redux.EnterGameAction
import org.luxons.sevenwonders.ui.redux.RequestStartGameAction
import org.luxons.sevenwonders.ui.redux.UpdateLobbyAction
+import org.luxons.sevenwonders.ui.router.Router
suspend fun SwSagaContext.lobbySaga(session: SevenWondersSession, lobbyId: Long) {
coroutineScope {
@@ -29,8 +30,7 @@ private suspend fun SwSagaContext.handleGameStart(session: SevenWondersSession,
coroutineScope {
launch { gameSaga(session, lobbyId) }
-
- // TODO push /game/{lobby.id}
+ Router.game(lobbyId)
}
}
diff --git a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/Sagas.kt b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/Sagas.kt
index 728a7d2f..1d15e8c4 100644
--- a/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/Sagas.kt
+++ b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/redux/sagas/Sagas.kt
@@ -6,6 +6,7 @@ import org.luxons.sevenwonders.client.SevenWondersClient
import org.luxons.sevenwonders.ui.redux.RequestChooseName
import org.luxons.sevenwonders.ui.redux.SetCurrentPlayerAction
import org.luxons.sevenwonders.ui.redux.SwState
+import org.luxons.sevenwonders.ui.router.Router
import redux.RAction
import redux.WrapperAction
@@ -21,6 +22,6 @@ suspend fun SwSagaContext.rootSaga() {
val player = session.chooseName(action.playerName)
dispatch(SetCurrentPlayerAction(player))
- // push /games
+ Router.games()
}
}
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
new file mode 100644
index 00000000..fa768cbf
--- /dev/null
+++ b/sw-ui-kt/src/main/kotlin/org/luxons/sevenwonders/ui/router/Router.kt
@@ -0,0 +1,22 @@
+package org.luxons.sevenwonders.ui.router
+
+import kotlin.browser.window
+
+object Router {
+
+ fun games() {
+ push("/games")
+ }
+
+ fun game(id: Long) {
+ push("/game/$id")
+ }
+
+ fun lobby(id: Long) {
+ push("/lobby/$id")
+ }
+
+ private fun push(path: String) {
+ window.location.hash = path
+ }
+}
bgstack15