mirror of
https://github.com/correl/planning-poker.git
synced 2024-11-21 19:18:37 +00:00
Submit entry forms upon pressing Enter
This commit is contained in:
parent
e347ade674
commit
acf1f812c8
3 changed files with 41 additions and 6 deletions
|
@ -43,7 +43,11 @@ update key msg model =
|
||||||
( { model | playerName = newName }, Cmd.none )
|
( { model | playerName = newName }, Cmd.none )
|
||||||
|
|
||||||
CreateRoom ->
|
CreateRoom ->
|
||||||
( model, Nav.pushUrl key ("/room/" ++ model.room) )
|
if not (String.isEmpty model.playerName) then
|
||||||
|
( model, Nav.pushUrl key ("/room/" ++ model.room) )
|
||||||
|
|
||||||
|
else
|
||||||
|
( model, Cmd.none )
|
||||||
|
|
||||||
|
|
||||||
view : Model -> Document Msg
|
view : Model -> Document Msg
|
||||||
|
@ -60,7 +64,7 @@ layout model =
|
||||||
[ width fill, centerY, spacing 30 ]
|
[ width fill, centerY, spacing 30 ]
|
||||||
[ el [ centerX ] (text "Oh, hey!")
|
[ el [ centerX ] (text "Oh, hey!")
|
||||||
, el [ centerX ] (text "Tell us who you are")
|
, el [ centerX ] (text "Tell us who you are")
|
||||||
, Input.text [ centerX, width (px 300) ]
|
, Input.text [ centerX, width (px 300), UI.onEnter CreateRoom ]
|
||||||
{ onChange = PlayerNameChanged
|
{ onChange = PlayerNameChanged
|
||||||
, text = model.playerName
|
, text = model.playerName
|
||||||
, label = Input.labelHidden "Your name"
|
, label = Input.labelHidden "Your name"
|
||||||
|
|
|
@ -151,9 +151,13 @@ update key msg model =
|
||||||
( { model | playerName = newName }, Cmd.none )
|
( { model | playerName = newName }, Cmd.none )
|
||||||
|
|
||||||
JoinRoom ->
|
JoinRoom ->
|
||||||
( { model | state = Playing }
|
if not (String.isEmpty model.playerName) then
|
||||||
, API.newProfile { playerName = model.playerName }
|
( { model | state = Playing }
|
||||||
)
|
, API.newProfile { playerName = model.playerName }
|
||||||
|
)
|
||||||
|
|
||||||
|
else
|
||||||
|
( model, Cmd.none )
|
||||||
|
|
||||||
GotPresence (Ok (PresenceState players)) ->
|
GotPresence (Ok (PresenceState players)) ->
|
||||||
let
|
let
|
||||||
|
@ -426,7 +430,12 @@ joinForm room playerName =
|
||||||
column [ width fill, spacing 20, centerX, centerY ]
|
column [ width fill, spacing 20, centerX, centerY ]
|
||||||
[ UI.heroText [ centerX ] "Welcome!"
|
[ UI.heroText [ centerX ] "Welcome!"
|
||||||
, el [ centerX ] (text "Tell us who you are")
|
, el [ centerX ] (text "Tell us who you are")
|
||||||
, Input.text [ centerX, width (px 300), Font.center ]
|
, Input.text
|
||||||
|
[ centerX
|
||||||
|
, width (px 300)
|
||||||
|
, Font.center
|
||||||
|
, UI.onEnter JoinRoom
|
||||||
|
]
|
||||||
{ onChange = PlayerNameChanged
|
{ onChange = PlayerNameChanged
|
||||||
, text = playerName
|
, text = playerName
|
||||||
, label = Input.labelHidden "Your name"
|
, label = Input.labelHidden "Your name"
|
||||||
|
|
|
@ -3,6 +3,7 @@ module PlanningPokerUI exposing
|
||||||
, colors
|
, colors
|
||||||
, fontSizes
|
, fontSizes
|
||||||
, heroText
|
, heroText
|
||||||
|
, onEnter
|
||||||
, toDocument
|
, toDocument
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -11,6 +12,8 @@ import Element exposing (..)
|
||||||
import Element.Background as Background
|
import Element.Background as Background
|
||||||
import Element.Font as Font
|
import Element.Font as Font
|
||||||
import Element.Input as Input
|
import Element.Input as Input
|
||||||
|
import Html.Events
|
||||||
|
import Json.Decode as Decode
|
||||||
|
|
||||||
|
|
||||||
colors =
|
colors =
|
||||||
|
@ -102,3 +105,22 @@ toDocument { title, body } =
|
||||||
column [ width fill, height fill, spacing 20 ] body
|
column [ width fill, height fill, spacing 20 ] body
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
onEnter : msg -> Element.Attribute msg
|
||||||
|
onEnter msg =
|
||||||
|
Element.htmlAttribute
|
||||||
|
(Html.Events.on "keyup"
|
||||||
|
(Decode.field
|
||||||
|
"key"
|
||||||
|
Decode.string
|
||||||
|
|> Decode.andThen
|
||||||
|
(\key ->
|
||||||
|
if key == "Enter" then
|
||||||
|
Decode.succeed msg
|
||||||
|
|
||||||
|
else
|
||||||
|
Decode.fail "Not the enter key"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue