participant

master
Josha von Gizycki 3 years ago
parent b965920ada
commit c084ee8e0a

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

@ -3,6 +3,7 @@ module Model exposing (InitInfo, Model, initialModel)
import Browser.Navigation as Nav
import Http
import Navigation
import Participant exposing (Participant)
import Url exposing (Url)
@ -15,9 +16,9 @@ type alias Model =
, apiHost : String
, route : Navigation.Route
, httpError : Maybe Http.Error
, userUuid : Uuid
, userName : String
, me : Participant
, session : Maybe String
, participants : List Participant
}
@ -37,12 +38,12 @@ initialModel init =
init.route
-- httpError
Maybe.Nothing
-- userUuid
init.userUuid
-- userName
""
-- me
(Participant init.userUuid "")
-- session
Maybe.Nothing
-- participants
[]
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 Json.Decode exposing (Decoder, andThen, decodeString, fail, field, map2, map3, string, succeed)
import Json.Encode as Enc
import Model exposing (Model)
import Participant as Participant exposing (Participant)
type Action
@ -39,15 +40,9 @@ strToAction str =
fail ("invalid action '" ++ str ++ "'")
type alias Publisher =
{ uuid : String
, name : String
}
type alias WsMessage =
{ action : Action
, publisher : Publisher
, publisher : Participant
, payload : String
}
@ -60,12 +55,7 @@ msgDecoder : Decoder WsMessage
msgDecoder =
map3 WsMessage
(field "action" string |> andThen strToAction)
(field "publisher"
(map2 Publisher
(field "uuid" string)
(field "name" string)
)
)
(field "publisher" Participant.decoder)
(field "payload" string)
@ -89,8 +79,8 @@ createSession model =
[ ( "action", Enc.string (actionToString CreateSession) )
, ( "publisher"
, Enc.object
[ ( "uuid", Enc.string model.userUuid )
, ( "name", Enc.string model.userName )
[ ( "id", Enc.string model.me.id )
, ( "name", Enc.string model.me.name )
]
)
, ( "payload", Enc.string "" )

Loading…
Cancel
Save