Clarify joining vs playing states

This commit is contained in:
Correl Roush 2020-05-06 21:33:41 -04:00
parent 6d51fb9632
commit c4bef81826
4 changed files with 31 additions and 27 deletions

View file

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

View file

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

View file

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

View file

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