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" import uuid4 from "uuid4"
var player_id = uuid4() var player_id = uuid4()
var room_id = uuid4()
var socket = new Socket("/socket", {params: {player_id: player_id}}) var socket = new Socket("/socket", {params: {player_id: player_id}})
socket.connect() socket.connect()
var app = Elm.Main.init({ var app = Elm.Main.init({
node: document.getElementById("elm-main"), node: document.getElementById("elm-main"),
flags: "player:" + player_id flags: {
player: "player:" + player_id,
room: room_id
}
}) })
app.ports.joinRoom.subscribe(options => { app.ports.joinRoom.subscribe(options => {

View file

@ -10,10 +10,17 @@ import Url exposing (Url)
import Url.Parser as Parser exposing ((</>), Parser, s, string) import Url.Parser as Parser exposing ((</>), Parser, s, string)
type alias Flags =
{ player : String
, room : String
}
type alias Model = type alias Model =
{ page : Page { page : Page
, key : Nav.Key , key : Nav.Key
, player : String , player : String
, room : String
} }
@ -35,9 +42,14 @@ type Msg
| RoomMsg Room.Msg | RoomMsg Room.Msg
init : String -> Url -> Nav.Key -> ( Model, Cmd Msg ) init : Flags -> Url -> Nav.Key -> ( Model, Cmd Msg )
init player url key = init { player, room } url key =
updateUrl url { page = NotFound, key = key, player = player } updateUrl url
{ page = NotFound
, key = key
, player = player
, room = room
}
update : Msg -> Model -> ( Model, Cmd Msg ) update : Msg -> Model -> ( Model, Cmd Msg )
@ -77,7 +89,7 @@ updateUrl : Url -> Model -> ( Model, Cmd Msg )
updateUrl url model = updateUrl url model =
case Parser.parse parser url of case Parser.parse parser url of
Just Entry -> Just Entry ->
toEntry model (Entry.init ()) toEntry model (Entry.init model.room)
Just (Room id) -> Just (Room id) ->
case model.page of case model.page of
@ -130,7 +142,7 @@ view model =
NotFound.view NotFound.view
main : Program String Model Msg main : Program Flags Model Msg
main = main =
Browser.application Browser.application
{ init = init { init = init

View file

@ -13,7 +13,8 @@ import PlanningPokerUI as UI
type alias Model = type alias Model =
{ playerName : String { room : String
, playerName : String
, player : Maybe String , player : Maybe String
, error : Maybe String , error : Maybe String
} }
@ -24,9 +25,10 @@ type Msg
| CreateRoom | CreateRoom
init : () -> ( Model, Cmd Msg ) init : String -> ( Model, Cmd Msg )
init _ = init room =
( { playerName = "" ( { room = room
, playerName = ""
, player = Nothing , player = Nothing
, error = Nothing , error = Nothing
} }
@ -41,11 +43,7 @@ update key msg model =
( { model | playerName = newName }, Cmd.none ) ( { model | playerName = newName }, Cmd.none )
CreateRoom -> CreateRoom ->
let ( model, Nav.pushUrl key ("/room/" ++ model.room) )
room =
"a0fd1422-abd9-434e-9d7c-883294b2992c"
in
( model, Nav.pushUrl key ("/room/" ++ room) )
view : Model -> Document Msg view : Model -> Document Msg