mirror of
https://github.com/correl/planning-poker.git
synced 2024-11-22 03:00:12 +00:00
Remove hard-coded room id
This commit is contained in:
parent
b5dea51863
commit
9cf1604db0
3 changed files with 29 additions and 15 deletions
|
@ -19,13 +19,17 @@ import { Elm } from "../src/Main.elm"
|
|||
import uuid4 from "uuid4"
|
||||
|
||||
var player_id = uuid4()
|
||||
var room_id = uuid4()
|
||||
|
||||
var socket = new Socket("/socket", {params: {player_id: player_id}})
|
||||
socket.connect()
|
||||
|
||||
var app = Elm.Main.init({
|
||||
node: document.getElementById("elm-main"),
|
||||
flags: "player:" + player_id
|
||||
flags: {
|
||||
player: "player:" + player_id,
|
||||
room: room_id
|
||||
}
|
||||
})
|
||||
|
||||
app.ports.joinRoom.subscribe(options => {
|
||||
|
|
|
@ -10,10 +10,17 @@ import Url exposing (Url)
|
|||
import Url.Parser as Parser exposing ((</>), Parser, s, string)
|
||||
|
||||
|
||||
type alias Flags =
|
||||
{ player : String
|
||||
, room : String
|
||||
}
|
||||
|
||||
|
||||
type alias Model =
|
||||
{ page : Page
|
||||
, key : Nav.Key
|
||||
, player : String
|
||||
, room : String
|
||||
}
|
||||
|
||||
|
||||
|
@ -35,9 +42,14 @@ type Msg
|
|||
| RoomMsg Room.Msg
|
||||
|
||||
|
||||
init : String -> Url -> Nav.Key -> ( Model, Cmd Msg )
|
||||
init player url key =
|
||||
updateUrl url { page = NotFound, key = key, player = player }
|
||||
init : Flags -> Url -> Nav.Key -> ( Model, Cmd Msg )
|
||||
init { player, room } url key =
|
||||
updateUrl url
|
||||
{ page = NotFound
|
||||
, key = key
|
||||
, player = player
|
||||
, room = room
|
||||
}
|
||||
|
||||
|
||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||
|
@ -77,7 +89,7 @@ updateUrl : Url -> Model -> ( Model, Cmd Msg )
|
|||
updateUrl url model =
|
||||
case Parser.parse parser url of
|
||||
Just Entry ->
|
||||
toEntry model (Entry.init ())
|
||||
toEntry model (Entry.init model.room)
|
||||
|
||||
Just (Room id) ->
|
||||
case model.page of
|
||||
|
@ -130,7 +142,7 @@ view model =
|
|||
NotFound.view
|
||||
|
||||
|
||||
main : Program String Model Msg
|
||||
main : Program Flags Model Msg
|
||||
main =
|
||||
Browser.application
|
||||
{ init = init
|
||||
|
|
|
@ -13,7 +13,8 @@ import PlanningPokerUI as UI
|
|||
|
||||
|
||||
type alias Model =
|
||||
{ playerName : String
|
||||
{ room : String
|
||||
, playerName : String
|
||||
, player : Maybe String
|
||||
, error : Maybe String
|
||||
}
|
||||
|
@ -24,9 +25,10 @@ type Msg
|
|||
| CreateRoom
|
||||
|
||||
|
||||
init : () -> ( Model, Cmd Msg )
|
||||
init _ =
|
||||
( { playerName = ""
|
||||
init : String -> ( Model, Cmd Msg )
|
||||
init room =
|
||||
( { room = room
|
||||
, playerName = ""
|
||||
, player = Nothing
|
||||
, error = Nothing
|
||||
}
|
||||
|
@ -41,11 +43,7 @@ update key msg model =
|
|||
( { model | playerName = newName }, Cmd.none )
|
||||
|
||||
CreateRoom ->
|
||||
let
|
||||
room =
|
||||
"a0fd1422-abd9-434e-9d7c-883294b2992c"
|
||||
in
|
||||
( model, Nav.pushUrl key ("/room/" ++ room) )
|
||||
( model, Nav.pushUrl key ("/room/" ++ model.room) )
|
||||
|
||||
|
||||
view : Model -> Document Msg
|
||||
|
|
Loading…
Reference in a new issue