From c4bef818264f397b58eb4d110d69bed9a3023df3 Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Wed, 6 May 2020 21:33:41 -0400 Subject: [PATCH] Clarify joining vs playing states --- assets/js/app.js | 1 - assets/src/Main.elm | 3 +-- assets/src/PlanningPokerEntry.elm | 15 ------------ assets/src/PlanningPokerRoom.elm | 39 ++++++++++++++++++++++++------- 4 files changed, 31 insertions(+), 27 deletions(-) diff --git a/assets/js/app.js b/assets/js/app.js index 1bab9f2..e906482 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -47,7 +47,6 @@ app.ports.joinRoom.subscribe(options => { channel.join() .receive("ok", resp => { console.log("Joined successfully", resp); - app.ports.joinedRoom.send(options.room); }) .receive("error", resp => { console.log("Unable to join", resp) }) diff --git a/assets/src/Main.elm b/assets/src/Main.elm index cc050f7..15097b0 100644 --- a/assets/src/Main.elm +++ b/assets/src/Main.elm @@ -145,6 +145,5 @@ main = subscriptions : Model -> Sub Msg subscriptions _ = Sub.batch - [ Sub.map EntryMsg Entry.subscriptions - , Sub.map RoomMsg Room.subscriptions + [ Sub.map RoomMsg Room.subscriptions ] diff --git a/assets/src/PlanningPokerEntry.elm b/assets/src/PlanningPokerEntry.elm index 676bed9..3f42c2e 100644 --- a/assets/src/PlanningPokerEntry.elm +++ b/assets/src/PlanningPokerEntry.elm @@ -22,7 +22,6 @@ type alias Model = type Msg = PlayerNameChanged String | CreateRoom - | JoinedRoom String init : () -> ( Model, Cmd Msg ) @@ -41,20 +40,11 @@ update key msg model = PlayerNameChanged newName -> ( { model | playerName = newName }, Cmd.none ) - CreateRoom -> let room = "a0fd1422-abd9-434e-9d7c-883294b2992c" in - ( model - , Cmd.batch - [ API.joinRoom { room = room } - , API.newProfile { playerName = model.playerName } - ] - ) - - JoinedRoom room -> ( model, Nav.pushUrl key ("/room/" ++ room) ) @@ -94,8 +84,3 @@ layout model = <| text (Maybe.withDefault " " model.error) ] - - -subscriptions : Sub Msg -subscriptions = - API.joinedRoom JoinedRoom diff --git a/assets/src/PlanningPokerRoom.elm b/assets/src/PlanningPokerRoom.elm index f86c4f2..54541c6 100644 --- a/assets/src/PlanningPokerRoom.elm +++ b/assets/src/PlanningPokerRoom.elm @@ -22,13 +22,19 @@ import PlanningPokerUI as UI type alias Model = - { room : Room + { state : State + , room : Room , player : String , playerName : String , showVotes : Bool } +type State + = Joining + | Playing + + type Msg = Vote String | Reset @@ -76,13 +82,26 @@ init { id, player, roomName, playerName } = , name = roomName , players = Dict.empty } + + ( state, cmd ) = + if String.isEmpty playerName then + ( Joining, API.joinRoom { room = id } ) + + else + ( Playing + , Cmd.batch + [ API.joinRoom { room = id } + , API.newProfile { playerName = playerName } + ] + ) in ( { room = room + , state = state , player = player , playerName = playerName , showVotes = False } - , API.joinRoom { room = id } + , cmd ) @@ -130,7 +149,7 @@ update key msg model = ( { model | playerName = newName }, Cmd.none ) JoinRoom -> - ( model + ( { model | state = Playing } , API.newProfile { playerName = model.playerName } ) @@ -150,24 +169,26 @@ update key msg model = view : Model -> Document Msg view model = let - maybePlayer = + playerName = Dict.get model.player model.room.players + |> Maybe.map .name + |> Maybe.withDefault model.playerName in - case maybePlayer of - Just player -> + case model.state of + Playing -> UI.toDocument { title = model.room.name , body = - [ navBar { title = model.room.name, playerName = player.name } + [ navBar { title = model.room.name, playerName = playerName } , viewRoom model.player model.room model.showVotes ] } - Nothing -> + Joining -> UI.toDocument { title = model.room.name , body = - [ navBar { title = model.room.name, playerName = "" } + [ navBar { title = model.room.name, playerName = playerName } , joinForm model.room model.playerName ] }