From 882d56ce662f55c8d2779f4c401c79106abcbd92 Mon Sep 17 00:00:00 2001 From: towards-a-new-leftypol Date: Tue, 12 Mar 2024 18:23:27 -0400 Subject: [PATCH] Get basic response working - now need to hook up the views from Common --- app/Common | 2 +- app/Main.hs | 65 ++++++++++++++++++++++++++++++++++++++++++-- chandlr-server.cabal | 4 ++- 3 files changed, 66 insertions(+), 5 deletions(-) diff --git a/app/Common b/app/Common index 7d521a9..b01e4e2 160000 --- a/app/Common +++ b/app/Common @@ -1 +1 @@ -Subproject commit 7d521a921990b5a05d98782babc85cc6ee54eb0c +Subproject commit b01e4e269613fc0a69c9728a18a0bcdf1a0562a9 diff --git a/app/Main.hs b/app/Main.hs index 1929475..c831fef 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,22 +1,81 @@ +{-# LANGUAGE OverloadedStrings #-} + module Main where -import Miso (ToServerRoutes) +import Control.Monad.IO.Class (liftIO) +import Data.Text (Text) +import Miso (ToServerRoutes, View, h1_, text) import Data.Proxy import qualified Network.Wai as Wai import qualified Network.Wai.Handler.Warp as Wai import qualified Network.Wai.Middleware.RequestLogger as Wai import Servant.API +import Servant.Server (Server, Handler (..), serve) +import qualified Lucid as L +import qualified Lucid.Base as L + import qualified Common.FrontEnd.Routes as FE import qualified Common.FrontEnd.Action as FE +import qualified Common.FrontEnd.Model as FE newtype HtmlPage a = HtmlPage a - -- deriving (Show, Eq) + +instance (L.ToHtml a) => L.ToHtml (HtmlPage a) where + toHtmlRaw = L.toHtml + toHtml (HtmlPage x) = L.toHtml x + -- toHtml (HtmlPage x) = do + -- L.doctype_ + -- L.head_ $ do + -- L.title_ "Chandlr" + -- L.meta_ [L.charset_ "utf-8"] + + -- L.with (L.script_ mempty) + -- [ L.makeAttribute "src" "/static/all.js" + -- , L.makeAttribute "async" mempty + -- , L.makeAttribute "defer" mempty + -- ] + + -- L.body_ (L.toHtml x) type FrontEndRoutes = ToServerRoutes FE.Route HtmlPage FE.Action +handlers :: Server FrontEndRoutes +handlers = catalogView :<|> threadView :<|> searchView + +catalogView :: Handler (HtmlPage (View FE.Action)) +catalogView = do + liftIO $ putStrLn "Hello World" + + pure $ HtmlPage $ h1_ [] [ text "Hello World" ] + +{- + return $ HtmlPage $ do + L.doctype_ + L.head_ $ do + L.title_ "Chandlr" + L.meta_ [L.charset_ "utf-8"] + + L.with (L.script_ mempty) + [ L.makeAttribute "src" "/static/all.js" + , L.makeAttribute "async" mempty + , L.makeAttribute "defer" mempty + ] + + L.body_ (L.h1_ "Hello World") +-} + +threadView :: Text -> Text -> FE.BoardThreadId -> Handler (HtmlPage (View FE.Action)) +threadView = undefined + +searchView :: Maybe Text -> Handler (HtmlPage (View FE.Action)) +searchView = undefined + +viewPage :: FE.Model -> View FE.Action +viewPage = undefined + app :: Wai.Application -app = undefined +app = serve (Proxy @FrontEndRoutes) handlers port :: Int port = 8888 diff --git a/chandlr-server.cabal b/chandlr-server.cabal index 675b206..bd466a3 100644 --- a/chandlr-server.cabal +++ b/chandlr-server.cabal @@ -104,7 +104,9 @@ executable chandlr-server parsec, filepath, containers, - servant + servant, + servant-server, + lucid -- Directories containing source files. hs-source-dirs: app