mirror of
https://github.com/correl/planning-poker.git
synced 2024-11-25 03:00:12 +00:00
Clarify joining vs playing states
This commit is contained in:
parent
6d51fb9632
commit
c4bef81826
4 changed files with 31 additions and 27 deletions
|
@ -47,7 +47,6 @@ app.ports.joinRoom.subscribe(options => {
|
||||||
channel.join()
|
channel.join()
|
||||||
.receive("ok", resp => {
|
.receive("ok", resp => {
|
||||||
console.log("Joined successfully", resp);
|
console.log("Joined successfully", resp);
|
||||||
app.ports.joinedRoom.send(options.room);
|
|
||||||
})
|
})
|
||||||
.receive("error", resp => { console.log("Unable to join", resp) })
|
.receive("error", resp => { console.log("Unable to join", resp) })
|
||||||
|
|
||||||
|
|
|
@ -145,6 +145,5 @@ main =
|
||||||
subscriptions : Model -> Sub Msg
|
subscriptions : Model -> Sub Msg
|
||||||
subscriptions _ =
|
subscriptions _ =
|
||||||
Sub.batch
|
Sub.batch
|
||||||
[ Sub.map EntryMsg Entry.subscriptions
|
[ Sub.map RoomMsg Room.subscriptions
|
||||||
, Sub.map RoomMsg Room.subscriptions
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -22,7 +22,6 @@ type alias Model =
|
||||||
type Msg
|
type Msg
|
||||||
= PlayerNameChanged String
|
= PlayerNameChanged String
|
||||||
| CreateRoom
|
| CreateRoom
|
||||||
| JoinedRoom String
|
|
||||||
|
|
||||||
|
|
||||||
init : () -> ( Model, Cmd Msg )
|
init : () -> ( Model, Cmd Msg )
|
||||||
|
@ -41,20 +40,11 @@ update key msg model =
|
||||||
PlayerNameChanged newName ->
|
PlayerNameChanged newName ->
|
||||||
( { model | playerName = newName }, Cmd.none )
|
( { model | playerName = newName }, Cmd.none )
|
||||||
|
|
||||||
|
|
||||||
CreateRoom ->
|
CreateRoom ->
|
||||||
let
|
let
|
||||||
room =
|
room =
|
||||||
"a0fd1422-abd9-434e-9d7c-883294b2992c"
|
"a0fd1422-abd9-434e-9d7c-883294b2992c"
|
||||||
in
|
in
|
||||||
( model
|
|
||||||
, Cmd.batch
|
|
||||||
[ API.joinRoom { room = room }
|
|
||||||
, API.newProfile { playerName = model.playerName }
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
JoinedRoom room ->
|
|
||||||
( model, Nav.pushUrl key ("/room/" ++ room) )
|
( model, Nav.pushUrl key ("/room/" ++ room) )
|
||||||
|
|
||||||
|
|
||||||
|
@ -94,8 +84,3 @@ layout model =
|
||||||
<|
|
<|
|
||||||
text (Maybe.withDefault " " model.error)
|
text (Maybe.withDefault " " model.error)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
subscriptions : Sub Msg
|
|
||||||
subscriptions =
|
|
||||||
API.joinedRoom JoinedRoom
|
|
||||||
|
|
|
@ -22,13 +22,19 @@ import PlanningPokerUI as UI
|
||||||
|
|
||||||
|
|
||||||
type alias Model =
|
type alias Model =
|
||||||
{ room : Room
|
{ state : State
|
||||||
|
, room : Room
|
||||||
, player : String
|
, player : String
|
||||||
, playerName : String
|
, playerName : String
|
||||||
, showVotes : Bool
|
, showVotes : Bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
type State
|
||||||
|
= Joining
|
||||||
|
| Playing
|
||||||
|
|
||||||
|
|
||||||
type Msg
|
type Msg
|
||||||
= Vote String
|
= Vote String
|
||||||
| Reset
|
| Reset
|
||||||
|
@ -76,13 +82,26 @@ init { id, player, roomName, playerName } =
|
||||||
, name = roomName
|
, name = roomName
|
||||||
, players = Dict.empty
|
, 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
|
in
|
||||||
( { room = room
|
( { room = room
|
||||||
|
, state = state
|
||||||
, player = player
|
, player = player
|
||||||
, playerName = playerName
|
, playerName = playerName
|
||||||
, showVotes = False
|
, showVotes = False
|
||||||
}
|
}
|
||||||
, API.joinRoom { room = id }
|
, cmd
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -130,7 +149,7 @@ update key msg model =
|
||||||
( { model | playerName = newName }, Cmd.none )
|
( { model | playerName = newName }, Cmd.none )
|
||||||
|
|
||||||
JoinRoom ->
|
JoinRoom ->
|
||||||
( model
|
( { model | state = Playing }
|
||||||
, API.newProfile { playerName = model.playerName }
|
, API.newProfile { playerName = model.playerName }
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -150,24 +169,26 @@ update key msg model =
|
||||||
view : Model -> Document Msg
|
view : Model -> Document Msg
|
||||||
view model =
|
view model =
|
||||||
let
|
let
|
||||||
maybePlayer =
|
playerName =
|
||||||
Dict.get model.player model.room.players
|
Dict.get model.player model.room.players
|
||||||
|
|> Maybe.map .name
|
||||||
|
|> Maybe.withDefault model.playerName
|
||||||
in
|
in
|
||||||
case maybePlayer of
|
case model.state of
|
||||||
Just player ->
|
Playing ->
|
||||||
UI.toDocument
|
UI.toDocument
|
||||||
{ title = model.room.name
|
{ title = model.room.name
|
||||||
, body =
|
, body =
|
||||||
[ navBar { title = model.room.name, playerName = player.name }
|
[ navBar { title = model.room.name, playerName = playerName }
|
||||||
, viewRoom model.player model.room model.showVotes
|
, viewRoom model.player model.room model.showVotes
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
Nothing ->
|
Joining ->
|
||||||
UI.toDocument
|
UI.toDocument
|
||||||
{ title = model.room.name
|
{ title = model.room.name
|
||||||
, body =
|
, body =
|
||||||
[ navBar { title = model.room.name, playerName = "" }
|
[ navBar { title = model.room.name, playerName = playerName }
|
||||||
, joinForm model.room model.playerName
|
, joinForm model.room model.playerName
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue