participant

master
Josha von Gizycki 3 years ago
parent b965920ada
commit c084ee8e0a

@ -158,10 +158,24 @@ update msg model =
-- INIT -- INIT
NameChanged name -> NameChanged name ->
( { model | userName = name }, Cmd.none ) let
me =
model.me
newme =
{ me | name = name }
in
( { model | me = newme }, Cmd.none )
NameGenerated scrambled -> NameGenerated scrambled ->
( { model | userName = scrambled.prefix ++ " " ++ scrambled.suffix }, Cmd.none ) let
me =
model.me
newme =
{ me | name = scrambled.prefix ++ " " ++ scrambled.suffix }
in
( { model | me = newme }, Cmd.none )
RandomizeName -> RandomizeName ->
( model, randomUserName ) ( model, randomUserName )
@ -202,7 +216,7 @@ view model =
[ h1 [ class "app-title" ] [ text "Open-Retro" ] [ h1 [ class "app-title" ] [ text "Open-Retro" ]
, ul [] , ul []
[ li [] [ li []
[ input [ onInput NameChanged, value model.userName ] [ input [ onInput NameChanged, value model.me.name ]
[] []
] ]
, li [] , li []
@ -245,4 +259,5 @@ homePage _ =
pokerPage : Model -> List (Html Msg) pokerPage : Model -> List (Html Msg)
pokerPage _ = pokerPage _ =
[] [ ul [] []
]

@ -3,6 +3,7 @@ module Model exposing (InitInfo, Model, initialModel)
import Browser.Navigation as Nav import Browser.Navigation as Nav
import Http import Http
import Navigation import Navigation
import Participant exposing (Participant)
import Url exposing (Url) import Url exposing (Url)
@ -15,9 +16,9 @@ type alias Model =
, apiHost : String , apiHost : String
, route : Navigation.Route , route : Navigation.Route
, httpError : Maybe Http.Error , httpError : Maybe Http.Error
, userUuid : Uuid , me : Participant
, userName : String
, session : Maybe String , session : Maybe String
, participants : List Participant
} }
@ -37,12 +38,12 @@ initialModel init =
init.route init.route
-- httpError -- httpError
Maybe.Nothing Maybe.Nothing
-- userUuid -- me
init.userUuid (Participant init.userUuid "")
-- userName
""
-- session -- session
Maybe.Nothing Maybe.Nothing
-- participants
[]
urlToPort : Url -> String urlToPort : Url -> String

@ -0,0 +1,26 @@
module Participant exposing (Participant, decoder)
import Json.Decode exposing (Decoder, field, map2, string)
import Json.Encode as Enc exposing (object)
type alias Participant =
{ id : String
, name : String
}
decoder : Decoder Participant
decoder =
map2 Participant
(field "id" string)
(field "name" string)
encode : Participant -> String
encode participant =
object
[ ( "id", Enc.string participant.id )
, ( "name", Enc.string participant.name )
]
|> Enc.encode 0

@ -1,9 +1,10 @@
module WsMessage exposing (Action(..), Publisher, WsMessage, createSession, decode, msgDecoder, strToAction) module WsMessage exposing (Action(..), WsMessage, createSession, decode, msgDecoder, strToAction)
import Dict exposing (Dict) import Dict exposing (Dict)
import Json.Decode exposing (Decoder, andThen, decodeString, fail, field, map2, map3, string, succeed) import Json.Decode exposing (Decoder, andThen, decodeString, fail, field, map2, map3, string, succeed)
import Json.Encode as Enc import Json.Encode as Enc
import Model exposing (Model) import Model exposing (Model)
import Participant as Participant exposing (Participant)
type Action type Action
@ -39,15 +40,9 @@ strToAction str =
fail ("invalid action '" ++ str ++ "'") fail ("invalid action '" ++ str ++ "'")
type alias Publisher =
{ uuid : String
, name : String
}
type alias WsMessage = type alias WsMessage =
{ action : Action { action : Action
, publisher : Publisher , publisher : Participant
, payload : String , payload : String
} }
@ -60,12 +55,7 @@ msgDecoder : Decoder WsMessage
msgDecoder = msgDecoder =
map3 WsMessage map3 WsMessage
(field "action" string |> andThen strToAction) (field "action" string |> andThen strToAction)
(field "publisher" (field "publisher" Participant.decoder)
(map2 Publisher
(field "uuid" string)
(field "name" string)
)
)
(field "payload" string) (field "payload" string)
@ -89,8 +79,8 @@ createSession model =
[ ( "action", Enc.string (actionToString CreateSession) ) [ ( "action", Enc.string (actionToString CreateSession) )
, ( "publisher" , ( "publisher"
, Enc.object , Enc.object
[ ( "uuid", Enc.string model.userUuid ) [ ( "id", Enc.string model.me.id )
, ( "name", Enc.string model.userName ) , ( "name", Enc.string model.me.name )
] ]
) )
, ( "payload", Enc.string "" ) , ( "payload", Enc.string "" )

Loading…
Cancel
Save