Remove hard-coded room id

This commit is contained in:
Correl Roush 2020-05-06 22:02:44 -04:00
parent b5dea51863
commit 9cf1604db0
3 changed files with 29 additions and 15 deletions

View file

@ -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 => {

View file

@ -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

View file

@ -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