From 780527946548c68bfcfc4d8a99abf06b66cf23c1 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Wed, 29 Jul 2020 16:17:17 +0200 Subject: Stub client --- .gitignore | 2 ++ Makefile | 22 +++++++++++++++++----- client/elm.json | 24 ++++++++++++++++++++++++ client/index.html | 9 +++++++++ client/src/Client.elm | 13 +++++++++++++ server/lib/Cafp/Main/Server.hs | 3 ++- 6 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 client/elm.json create mode 100644 client/index.html create mode 100644 client/src/Client.elm diff --git a/.gitignore b/.gitignore index e463d23..a38e4dd 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /server/.stack-work/ +/server/assets/ +/client/elm-stuff/ diff --git a/Makefile b/Makefile index 677f1b6..5c05542 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,24 @@ HS_SOURCES=$(shell find server/lib/ server/src -name '*.hs') -ELM_MESSAGES_MODULE=client/src/Messages.elm +ELM_SOURCES=$(shell find client/src -name '*.elm') +ELM_MESSAGES_SOURCE=client/src/Messages.elm .PHONY: build -build: - cd server && stack build +build: server/assets/client.js server/assets/client.html server: build cd server && stack exec cafp-server -$(ELM_MESSAGES_MODULE): $(HS_SOURCES) - (cd server && stack exec cafp-generate-elm-types) >$(ELM_MESSAGES_MODULE) +.PHONY: stack_build +stack_build: $(HS_SOURCES) + (cd server && stack build) + +$(ELM_MESSAGES_SOURCE): stack_build + (cd server && stack exec cafp-generate-elm-types) >$(ELM_MESSAGES_SOURCE) + +server/assets/client.js: $(ELM_MESSAGES_SOURCE) $(ELM_SOURCES) + mkdir -p server/assets + cd client && elm make src/Client.elm --output=../server/assets/client.js + +server/assets/client.html: client/index.html + mkdir -p server/assets + cp client/index.html $@ diff --git a/client/elm.json b/client/elm.json new file mode 100644 index 0000000..dea3450 --- /dev/null +++ b/client/elm.json @@ -0,0 +1,24 @@ +{ + "type": "application", + "source-directories": [ + "src" + ], + "elm-version": "0.19.1", + "dependencies": { + "direct": { + "elm/browser": "1.0.2", + "elm/core": "1.0.5", + "elm/html": "1.0.0" + }, + "indirect": { + "elm/json": "1.1.3", + "elm/time": "1.0.0", + "elm/url": "1.0.0", + "elm/virtual-dom": "1.0.2" + } + }, + "test-dependencies": { + "direct": {}, + "indirect": {} + } +} diff --git a/client/index.html b/client/index.html new file mode 100644 index 0000000..8ac103a --- /dev/null +++ b/client/index.html @@ -0,0 +1,9 @@ + + + + + Client + + + + diff --git a/client/src/Client.elm b/client/src/Client.elm new file mode 100644 index 0000000..1db70c7 --- /dev/null +++ b/client/src/Client.elm @@ -0,0 +1,13 @@ +module Client exposing (main) + +import Browser +import Html + +main : Program () () msg +main = Browser.element + { init = \() -> ((), Cmd.none) + , update = \_ model -> (model, Cmd.none) + , subscriptions = \_ -> Sub.none + , view = \model -> Html.h1 [] [Html.text "Hi"] + } + diff --git a/server/lib/Cafp/Main/Server.hs b/server/lib/Cafp/Main/Server.hs index a2561a3..5de7403 100644 --- a/server/lib/Cafp/Main/Server.hs +++ b/server/lib/Cafp/Main/Server.hs @@ -26,4 +26,5 @@ main = Scotty.scotty 3000 $ do roomId <- Scotty.param "id" when (T.length roomId < 6) $ Scotty.raise "Room ID should be at least 6 characters" - Scotty.html $ "

Scotty, " <> TL.fromStrict roomId <> " me up!

" + Scotty.setHeader "Content-Type" "text/html" + Scotty.file "assets/client.html" -- cgit v1.2.3