now successfully decoding time
This commit is contained in:
parent
83d8196261
commit
a691de6567
|
@ -18,6 +18,8 @@ Now open `http://127.0.0.1:8080` in your browser.
|
||||||
# TODO
|
# TODO
|
||||||
|
|
||||||
- [x] Add Makefile
|
- [x] Add Makefile
|
||||||
|
- [ ] `EventHandlers.onMessage` should inject successfully decoded message into
|
||||||
|
Msg type directly...
|
||||||
- [ ] Run `uglify` twice as per [this link](https://github.com/rtfeldman/elm-spa-example/tree/master?tab=readme-ov-file#production-build)
|
- [ ] Run `uglify` twice as per [this link](https://github.com/rtfeldman/elm-spa-example/tree/master?tab=readme-ov-file#production-build)
|
||||||
- [ ] Clicking in upper left should go to landing page.
|
- [ ] Clicking in upper left should go to landing page.
|
||||||
- [ ] Add GPLV3 License
|
- [ ] Add GPLV3 License
|
||||||
|
|
|
@ -65,7 +65,6 @@ subscriptions model = Sub.batch
|
||||||
, model.page |> Body.subscriptions |> Sub.map Body
|
, model.page |> Body.subscriptions |> Sub.map Body
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
view : Model -> Browser.Document Msg
|
view : Model -> Browser.Document Msg
|
||||||
view model =
|
view model =
|
||||||
let
|
let
|
||||||
|
|
|
@ -7,20 +7,57 @@ module Page.Landing exposing
|
||||||
, subscriptions
|
, subscriptions
|
||||||
)
|
)
|
||||||
import Element exposing (Element)
|
import Element exposing (Element)
|
||||||
|
import Websockets
|
||||||
|
import Ports
|
||||||
|
import Json.Decode as Decode
|
||||||
|
|
||||||
type alias Model = {}
|
type alias Model = {
|
||||||
type alias Msg = {}
|
time : String
|
||||||
|
}
|
||||||
|
type Msg
|
||||||
|
= SocketOpened
|
||||||
|
| SocketClosed
|
||||||
|
| SocketMessage String
|
||||||
|
| NoOp
|
||||||
|
|
||||||
init : () -> Model
|
init : () -> Model
|
||||||
init flags = {}
|
init flags = {
|
||||||
|
time = "time not yet set"
|
||||||
|
}
|
||||||
|
|
||||||
|
decodeMessage : String -> String
|
||||||
|
decodeMessage message =
|
||||||
|
let
|
||||||
|
decodedMessage = Decode.decodeString (Decode.field "time" Decode.string) message
|
||||||
|
in
|
||||||
|
case decodedMessage of
|
||||||
|
Ok decoded -> decoded
|
||||||
|
Err err -> "failed to decode" ++ message
|
||||||
|
|
||||||
subscriptions : Model -> Sub Msg
|
subscriptions : Model -> Sub Msg
|
||||||
subscriptions _ = Sub.none
|
subscriptions model =
|
||||||
|
Ports.socketOnEvent
|
||||||
|
(Websockets.EventHandlers
|
||||||
|
(\_ -> SocketOpened)
|
||||||
|
(\_ -> SocketClosed)
|
||||||
|
(\_ -> NoOp)
|
||||||
|
(\message -> SocketMessage message.data)
|
||||||
|
(\_ -> NoOp)
|
||||||
|
)
|
||||||
|
|
||||||
update : Msg -> Model -> (Model, Cmd Msg)
|
update : Msg -> Model -> (Model, Cmd Msg)
|
||||||
update msg model = (model, Cmd.none)
|
update msg model =
|
||||||
|
case msg of
|
||||||
|
SocketMessage message ->
|
||||||
|
let
|
||||||
|
decoded = decodeMessage message
|
||||||
|
in
|
||||||
|
( {model | time = decoded}, Cmd.none )
|
||||||
|
_ -> (model, Cmd.none)
|
||||||
|
|
||||||
view : Model -> Element Msg
|
view : Model -> Element Msg
|
||||||
view model =
|
view model =
|
||||||
Element.el []
|
Element.column []
|
||||||
<| Element.text "Landing"
|
[ Element.text "Landing",
|
||||||
|
Element.text <| "Time is : " ++ model.time
|
||||||
|
]
|
||||||
|
|
Loading…
Reference in a new issue