diff --git a/README.md b/README.md index d26dfa4..817e41c 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ Now open `http://127.0.0.1:8080` in your browser. # TODO - [x] Add Makefile + - [ ] 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. - [ ] Add GPLV3 License - [ ] Add `make release` target that is nix ready... diff --git a/frontend/elm.json b/frontend/elm.json index c17e85d..9104ca4 100644 --- a/frontend/elm.json +++ b/frontend/elm.json @@ -9,12 +9,12 @@ "elm/browser": "1.0.2", "elm/core": "1.0.5", "elm/html": "1.0.0", + "elm/json": "1.1.3", "elm/url": "1.0.0", "kageurufu/elm-websockets": "1.0.1", "mdgriffith/elm-ui": "1.1.8" }, "indirect": { - "elm/json": "1.1.3", "elm/time": "1.0.0", "elm/virtual-dom": "1.0.3" } diff --git a/frontend/src/Main.elm b/frontend/src/Main.elm index ca91721..b99b58c 100644 --- a/frontend/src/Main.elm +++ b/frontend/src/Main.elm @@ -39,7 +39,7 @@ init flags url key = , header = header } in - (model, Cmd.none) + (model, Ports.socketOpen) update : Msg -> Model -> (Model, Cmd Msg) diff --git a/frontend/src/Page/About.elm b/frontend/src/Page/About.elm index 92c02a8..8b544e1 100644 --- a/frontend/src/Page/About.elm +++ b/frontend/src/Page/About.elm @@ -1,4 +1,12 @@ -module Page.About exposing (Model, Msg, view, init, update) +module Page.About exposing + ( Model + , Msg + , view + , init + , update + , subscriptions + , cleanupSubcriptions + ) import Element exposing (Element) type alias Model = {} @@ -7,6 +15,12 @@ type alias Msg = {} init : () -> Model init flags = {} +cleanupSubcriptions : Model -> Cmd Msg +cleanupSubcriptions _ = Cmd.none + +subscriptions : Model -> Sub Msg +subscriptions _ = Sub.none + update : Msg -> Model -> (Model, Cmd Msg) update msg model = (model, Cmd.none) diff --git a/frontend/src/Page/Contact.elm b/frontend/src/Page/Contact.elm index 3000024..eb0a201 100644 --- a/frontend/src/Page/Contact.elm +++ b/frontend/src/Page/Contact.elm @@ -1,4 +1,12 @@ -module Page.Contact exposing (Model, Msg, view, init, update) +module Page.Contact exposing + ( Model + , Msg + , view + , init + , update + , subscriptions + , cleanupSubcriptions + ) import Element exposing (Element) type alias Model = {} @@ -7,6 +15,13 @@ type alias Msg = {} init : () -> Model init flags = {} +cleanupSubcriptions : Model -> Cmd Msg +cleanupSubcriptions _ = Cmd.none + +subscriptions : Model -> Sub Msg +subscriptions _ = Sub.none + + update : Msg -> Model -> (Model, Cmd Msg) update msg model = (model, Cmd.none) diff --git a/frontend/src/Page/Landing.elm b/frontend/src/Page/Landing.elm index 3201232..47ddc9d 100644 --- a/frontend/src/Page/Landing.elm +++ b/frontend/src/Page/Landing.elm @@ -1,4 +1,12 @@ -module Page.Landing exposing (Model, Msg, view, init, update) +module Page.Landing exposing + ( Model + , Msg + , view + , init + , update + , subscriptions + , cleanupSubcriptions + ) import Element exposing (Element) type alias Model = {} @@ -7,6 +15,12 @@ type alias Msg = {} init : () -> Model init flags = {} +cleanupSubcriptions : Model -> Cmd Msg +cleanupSubcriptions _ = Cmd.none + +subscriptions : Model -> Sub Msg +subscriptions _ = Sub.none + update : Msg -> Model -> (Model, Cmd Msg) update msg model = (model, Cmd.none) diff --git a/frontend/src/Page/NotFound.elm b/frontend/src/Page/NotFound.elm index 2504e66..0b7badd 100644 --- a/frontend/src/Page/NotFound.elm +++ b/frontend/src/Page/NotFound.elm @@ -1,4 +1,12 @@ -module Page.NotFound exposing (Model, Msg, view, init, update) +module Page.NotFound exposing + ( Model + , Msg + , view + , init + , update + , subscriptions + , cleanupSubcriptions + ) import Element exposing (Element) type alias Model = {} @@ -7,6 +15,12 @@ type alias Msg = {} init : () -> Model init flags = {} +cleanupSubcriptions : Model -> Cmd Msg +cleanupSubcriptions _ = Cmd.none + +subscriptions : Model -> Sub Msg +subscriptions _ = Sub.none + update : Msg -> Model -> (Model, Cmd Msg) update msg model = (model, Cmd.none) diff --git a/frontend/src/Page/Products.elm b/frontend/src/Page/Products.elm index 125f98e..ea6d547 100644 --- a/frontend/src/Page/Products.elm +++ b/frontend/src/Page/Products.elm @@ -1,4 +1,12 @@ -module Page.Products exposing (Model, Msg, view, init, update) +module Page.Products exposing + ( Model + , Msg + , view + , init + , update + , subscriptions + , cleanupSubcriptions + ) import Element exposing (Element) type alias Model = {} @@ -7,6 +15,12 @@ type alias Msg = {} init : () -> Model init flags = {} +cleanupSubcriptions : Model -> Cmd Msg +cleanupSubcriptions _ = Cmd.none + +subscriptions : Model -> Sub Msg +subscriptions _ = Sub.none + update : Msg -> Model -> (Model, Cmd Msg) update msg model = (model, Cmd.none) diff --git a/frontend/src/Page/Resources.elm b/frontend/src/Page/Resources.elm index 2a7272c..84c32f9 100644 --- a/frontend/src/Page/Resources.elm +++ b/frontend/src/Page/Resources.elm @@ -1,4 +1,12 @@ -module Page.Resources exposing (Model, Msg, view, init, update) +module Page.Resources exposing + ( Model + , Msg + , view + , init + , update + , subscriptions + , cleanupSubcriptions + ) import Element exposing (Element) type alias Model = {} @@ -7,6 +15,12 @@ type alias Msg = {} init : () -> Model init flags = {} +cleanupSubcriptions : Model -> Cmd Msg +cleanupSubcriptions _ = Cmd.none + +subscriptions : Model -> Sub Msg +subscriptions _ = Sub.none + update : Msg -> Model -> (Model, Cmd Msg) update msg model = (model, Cmd.none) diff --git a/frontend/src/Ports.elm b/frontend/src/Ports.elm index be70672..a12d9ff 100644 --- a/frontend/src/Ports.elm +++ b/frontend/src/Ports.elm @@ -1,10 +1,28 @@ -port module Ports exposing (socket) +port module Ports exposing + ( socketOnEvent + , socketSend + , socketOpen + ) import Websockets +import Json.Encode as Encode port webSocketCommand : Websockets.CommandPort msg port webSocketEvent : Websockets.EventPort msg +socketName : String +socketName = "app" + +socketOnEvent : Websockets.EventHandlers msg -> Sub msg +socketOnEvent eventHandlers = + socket.onEvent eventHandlers + +socketSend : Encode.Value -> Cmd msg +socketSend data = socket.send socketName data + +socketOpen : Cmd msg +socketOpen = socket.open socketName "/ws/" [] + socket : Websockets.Methods msg socket = Websockets.withPorts