mirror of
https://github.com/correl/planning-poker.git
synced 2024-11-15 03:00:18 +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,8 +43,12 @@ update key msg model =
|
||||||
( { model | playerName = newName }, Cmd.none )
|
( { model | playerName = newName }, Cmd.none )
|
||||||
|
|
||||||
CreateRoom ->
|
CreateRoom ->
|
||||||
|
if not (String.isEmpty model.playerName) then
|
||||||
( model, Nav.pushUrl key ("/room/" ++ model.room) )
|
( model, Nav.pushUrl key ("/room/" ++ model.room) )
|
||||||
|
|
||||||
|
else
|
||||||
|
( model, Cmd.none )
|
||||||
|
|
||||||
|
|
||||||
view : Model -> Document Msg
|
view : Model -> Document Msg
|
||||||
view model =
|
view model =
|
||||||
|
@ -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,10 +151,14 @@ update key msg model =
|
||||||
( { model | playerName = newName }, Cmd.none )
|
( { model | playerName = newName }, Cmd.none )
|
||||||
|
|
||||||
JoinRoom ->
|
JoinRoom ->
|
||||||
|
if not (String.isEmpty model.playerName) then
|
||||||
( { model | state = Playing }
|
( { model | state = Playing }
|
||||||
, API.newProfile { playerName = model.playerName }
|
, API.newProfile { playerName = model.playerName }
|
||||||
)
|
)
|
||||||
|
|
||||||
|
else
|
||||||
|
( model, Cmd.none )
|
||||||
|
|
||||||
GotPresence (Ok (PresenceState players)) ->
|
GotPresence (Ok (PresenceState players)) ->
|
||||||
let
|
let
|
||||||
newRoom =
|
newRoom =
|
||||||
|
@ -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