From 92a7820a8ecf066b2e1cfa96b61141fba51336a9 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Thu, 13 Dec 2018 18:41:54 -0800 Subject: [PATCH] Add sending messages on enter. --- src/Scylla/Views.elm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Scylla/Views.elm b/src/Scylla/Views.elm index 9aeee8a..1e69e1d 100644 --- a/src/Scylla/Views.elm +++ b/src/Scylla/Views.elm @@ -8,9 +8,9 @@ import Svg import Svg.Attributes import Url.Builder 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.Events exposing (onInput, onClick) +import Html.Events exposing (onInput, onClick, on) import Dict stringColor : String -> String @@ -114,6 +114,7 @@ joinedRoomView m roomId jr = [ input [ type_ "text" , onInput <| ChangeRoomText roomId + , onEnterKey <| SendRoomText roomId , value <| Maybe.withDefault "" <| Dict.get roomId m.roomText ] [] , button [ onClick <| SendRoomText roomId ] [ iconView "send" ] @@ -126,6 +127,13 @@ joinedRoomView m roomId jr = , 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 name = let