From 9cf1604db0bb19c0dbd742a6e4f1a48ae7a1882d Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Wed, 6 May 2020 22:02:44 -0400 Subject: [PATCH] Remove hard-coded room id --- assets/js/app.js | 6 +++++- assets/src/Main.elm | 22 +++++++++++++++++----- assets/src/PlanningPokerEntry.elm | 16 +++++++--------- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/assets/js/app.js b/assets/js/app.js index e906482..dd075c1 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -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 => { diff --git a/assets/src/Main.elm b/assets/src/Main.elm index 15097b0..de47965 100644 --- a/assets/src/Main.elm +++ b/assets/src/Main.elm @@ -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 diff --git a/assets/src/PlanningPokerEntry.elm b/assets/src/PlanningPokerEntry.elm index 3f42c2e..765f61c 100644 --- a/assets/src/PlanningPokerEntry.elm +++ b/assets/src/PlanningPokerEntry.elm @@ -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