Add sending messages on enter.

This commit is contained in:
Danila Fedorin 2018-12-13 18:41:54 -08:00
parent 00b6462fe4
commit 92a7820a8e

View File

@ -8,9 +8,9 @@ import Svg
import Svg.Attributes import Svg.Attributes
import Url.Builder import Url.Builder
import Json.Decode as Decode import Json.Decode as Decode
import Html exposing (Html, div, input, text, button, div, span, a, h2, table, td, tr) import Html exposing (Html, Attribute, div, input, text, button, div, span, a, h2, table, td, tr)
import Html.Attributes exposing (type_, value, href, class, style) import Html.Attributes exposing (type_, value, href, class, style)
import Html.Events exposing (onInput, onClick) import Html.Events exposing (onInput, onClick, on)
import Dict import Dict
stringColor : String -> String stringColor : String -> String
@ -114,6 +114,7 @@ joinedRoomView m roomId jr =
[ input [ input
[ type_ "text" [ type_ "text"
, onInput <| ChangeRoomText roomId , onInput <| ChangeRoomText roomId
, onEnterKey <| SendRoomText roomId
, value <| Maybe.withDefault "" <| Dict.get roomId m.roomText , value <| Maybe.withDefault "" <| Dict.get roomId m.roomText
] [] ] []
, button [ onClick <| SendRoomText roomId ] [ iconView "send" ] , button [ onClick <| SendRoomText roomId ] [ iconView "send" ]
@ -126,6 +127,13 @@ joinedRoomView m roomId jr =
, messageInput , messageInput
] ]
onEnterKey : Msg -> Attribute Msg
onEnterKey msg =
let
isEnter code = if code == 13 then Decode.succeed msg else Decode.fail "Not ENTER"
in
on "keydown" (Decode.andThen isEnter <| Decode.field "keyCode" Decode.int)
iconView : String -> Html Msg iconView : String -> Html Msg
iconView name = iconView name =
let let