master
Josha von Gizycki 3 years ago
parent a036372335
commit 0a75805e1a

3
.gitignore vendored

@ -7,3 +7,6 @@
/frontend/compiled/
backend/.nrepl-port
.idea/sonarlint
/frontend/frontend.iml
/backend/backend.iml
.idea

@ -2,7 +2,9 @@
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<content url="file://$MODULE_DIR$">
<excludePattern pattern="elm-stuff" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>

@ -33,8 +33,12 @@
}
})
let port = window.location.port
if(port === "8000") {
port = "8080"
}
const ws = new WebSocket(
"ws://" + window.location.hostname + ":" + window.location.port + "/ws")
"ws://" + window.location.hostname + ":" + port + "/ws")
ws.onmessage = function(event) {
console.debug(event)
app.ports.wsin.send(JSON.stringify(event.data))

@ -5,13 +5,16 @@
[hiccup.page :as h]))
(defn ws-endpoint [req]
(http-server/with-channel req channel
(println "ws incoming")
(http-server/with-channel
req channel
(http-server/on-close
channel
(fn [status] (println "closed" status)))
(http-server/on-receive
channel
(fn [data]
(println "received" data)
(http-server/send! channel data)))))
(def router
@ -34,7 +37,7 @@
server
(http-server/run-server
(fn [req]
(clojure.pprint/pprint req)
;(clojure.pprint/pprint req)
(router req))
{:port 8080})))

@ -1,4 +1,6 @@
// trio colour
$ciColor: #691487;
$ciColor: InfoBackground;
html {
font-family: sans-serif;
@ -29,7 +31,7 @@ nav {
margin: 0;
padding-left: .5em;
grid-area: title;
background-image: url("../img/klammer.svg");
//background-image: url("../img/klammer.svg");
background-repeat: no-repeat;
background-size: contain;
}

@ -2,7 +2,9 @@
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<content url="file://$MODULE_DIR$">
<excludePattern pattern="elm-stuff" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>

@ -80,8 +80,8 @@ update msg model =
WsOut wsmsg ->
( model, wsout wsmsg )
WsIn wsmsg ->
Debug.log wsmsg ( model, Cmd.none )
WsIn strmsg ->
( model, Cmd.none )
routeChanged : Navigation.Route -> Model -> ( Model, Cmd Msg )
@ -92,6 +92,11 @@ routeChanged route model =
, Cmd.none
)
Navigation.Poker session ->
( { model | route = route, session = Just session }
, Cmd.none
)
view : Model -> Browser.Document Msg
view model =
@ -101,11 +106,11 @@ view model =
[ h1 [ class "app-title" ] [ text "Open-Retro" ]
, ul []
[ li []
[ input [ class "board-search-input", placeholder "Board ID..." ] []
]
[ input [ class "board-search-input", placeholder "Session ID..." ] [] ]
, li []
[ text " New board"
]
[ text "🂿 New retro" ]
, li []
[ text "🃠 New poker" ]
]
]
, main_ [] (appContent model)
@ -120,7 +125,15 @@ appContent model =
Navigation.Home ->
homePage model
Navigation.Poker _ ->
pokerPage model
homePage : Model -> List (Html Msg)
homePage model =
homePage _ =
[]
pokerPage : Model -> List (Html Msg)
pokerPage _ =
[]

@ -16,6 +16,7 @@ type alias Model =
, route : Navigation.Route
, httpError : Maybe Http.Error
, userUuid : Uuid
, session : Maybe String
}
@ -37,6 +38,8 @@ initialModel init =
Maybe.Nothing
-- userUuid
init.userUuid
-- session
Maybe.Nothing
urlToPort : Url -> String

@ -2,8 +2,6 @@ module Navigation exposing (Route(..), linkClicked, routeParser)
import Browser
import Browser.Navigation as Nav
import Html exposing (Html, a, details, li, summary, text, ul)
import Html.Attributes as Attr exposing (href)
import Url
import Url.Parser exposing ((</>), Parser, map, oneOf, s, top)
@ -20,12 +18,14 @@ linkClicked urlRequest key model =
type Route
= Home
| Poker String
routeParser : Parser (Route -> Route) Route
routeParser =
oneOf
[ map Home top
, map Poker (s "poker" </> Url.Parser.string)
--, map ShowTicket (s "tickets" </> Url.Parser.int)
]

@ -0,0 +1,63 @@
module WsMessage exposing (..)
import Json.Decode exposing (Decoder, andThen, decodeString, fail, field, map2, map3, string, succeed)
type Action
= Publish
strToAction : String -> Decoder Action
strToAction str =
if str == "Publish" then
succeed Publish
else
fail ("invalid action '" ++ str ++ "'")
type alias Publisher =
{ uuid : String
, name : String
}
type alias WsMessage =
{ action : Action
, publisher : Publisher
, payload : String
}
-- DECODERS
publisherDecoder : Decoder Publisher
publisherDecoder =
map2 Publisher
(field "uuid" string)
(field "name" string)
msgDecoder : Decoder WsMessage
msgDecoder =
map3 WsMessage
actionDecoder
(field "publisher" publisherDecoder)
(field "payload" string)
actionDecoder : Decoder Action
actionDecoder =
field "action" string |> andThen strToAction
decode : String -> Maybe WsMessage
decode str =
case decodeString msgDecoder str of
Ok msg ->
Just msg
Err _ ->
Nothing
Loading…
Cancel
Save