Skip to content

Commit

Permalink
[NO-ISSUE] Enable live reload of pages upon server restart
Browse files Browse the repository at this point in the history
  • Loading branch information
tchoutri committed Sep 15, 2024
1 parent a59ebd6 commit 51f5f9c
Show file tree
Hide file tree
Showing 32 changed files with 2,210 additions and 1,937 deletions.
3 changes: 3 additions & 0 deletions assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
"esbuild": "^0.13.13",
"esbuild-copy-static-files": "^0.1.0",
"esbuild-plugin-assets-manifest": "^1.0.7",
"esbuild-sass-plugin": "^3.3.1",
"esbuild-style-plugin": "^1.6.0",
"htmx-ext-sse": "^2.2.2",
"livereload-js": "^4.0.2",
"postcss": "^8.4.31",
"postcss-cli": "^9.0.2",
"postcss-copy": "^7.1.0",
Expand Down
3,681 changes: 1,948 additions & 1,733 deletions assets/yarn.lock

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ tests: True
allow-newer: type-errors-pretty:base
, souffle-haskell:text
, servant-lucid:text
, lucid-svg:text
, lucid-svg:transformers
, lucid-aria:text
, lucid-alpine:text
, hashable:filepath

allow-older: pg-entity:time
Expand Down
28 changes: 16 additions & 12 deletions cabal.project.freeze
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ constraints: any.Cabal ==3.10.3.0,
any.comonad ==5.0.8,
comonad +containers +distributive +indexed-traversable,
any.concurrent-output ==1.10.21,
any.conduit ==1.3.5,
any.conduit ==1.3.6,
any.conduit-extra ==1.3.6,
any.constraints ==0.14.2,
any.containers ==0.6.7,
Expand All @@ -116,6 +116,7 @@ constraints: any.Cabal ==3.10.3.0,
any.cryptonite ==0.30,
cryptonite -check_alignment +integer-gmp -old_toolchain_inliner +support_aesni +support_deepseq -support_pclmuldq +support_rdrand -support_sse +use_target_attributes,
any.cryptonite-conduit ==0.2.2,
any.dani-servant-lucid2 ==0.1.0.0,
any.data-default ==0.7.1.1,
any.data-default-class ==0.1.2.0,
any.data-default-instances-containers ==0.0.1,
Expand Down Expand Up @@ -168,7 +169,7 @@ constraints: any.Cabal ==3.10.3.0,
any.haskell-src-meta ==0.8.14,
any.hdaemonize ==0.5.7,
any.heaps ==0.4,
any.hedgehog ==1.4,
any.hedgehog ==1.5,
any.hostname ==1.0,
any.hourglass ==0.2.12,
any.hpc ==0.6.2.0,
Expand All @@ -180,12 +181,14 @@ constraints: any.Cabal ==3.10.3.0,
any.hspec-expectations ==0.8.4,
any.hsyslog ==5.0.2,
hsyslog -install-examples,
any.htmx ==0.1.0.1,
any.htmx-lucid ==0.2.0.0,
any.http-api-data ==0.6.1,
http-api-data -use-text-show,
any.http-client ==0.7.17,
http-client +network-uri,
any.http-client-tls ==0.3.6.3,
any.http-conduit ==2.3.8.3,
any.http-conduit ==2.3.9,
http-conduit +aeson,
any.http-date ==0.0.11,
any.http-media ==0.8.1.1,
Expand Down Expand Up @@ -214,8 +217,7 @@ constraints: any.Cabal ==3.10.3.0,
any.log-base ==0.12.0.1,
any.log-effectful ==1.0.0.0,
any.lucid ==2.11.20230408,
any.lucid-alpine ==0.1.0.7,
any.lucid-svg ==0.7.2.0,
any.lucid2 ==0.0.20240424,
any.megaparsec ==9.6.1,
megaparsec -dev,
any.memory ==0.18.0,
Expand All @@ -232,7 +234,7 @@ constraints: any.Cabal ==3.10.3.0,
monad-loops +base4,
any.monad-time ==0.4.0.0,
any.monad-time-effectful ==1.0.0.0,
any.mono-traversable ==1.0.17.0,
any.mono-traversable ==1.0.20.0,
any.mtl ==2.3.1,
any.mtl-compat ==0.2.2,
mtl-compat -two-point-one -two-point-two,
Expand Down Expand Up @@ -311,14 +313,16 @@ constraints: any.Cabal ==3.10.3.0,
semigroups +binary +bytestring -bytestring-builder +containers +deepseq +hashable +tagged +template-haskell +text +transformers +unordered-containers,
any.serialise ==0.2.6.1,
serialise +newtime15,
any.servant ==0.20.1,
any.servant ==0.20.2,
any.servant-blaze ==0.9.1,
any.servant-client ==0.20,
any.servant-client-core ==0.20,
any.servant-client ==0.20.2,
any.servant-client-core ==0.20.2,
any.servant-effectful ==0.0.1.0,
any.servant-event-stream ==0.3.0.1,
any.servant-foreign ==0.16.1,
any.servant-lucid ==0.9.0.6,
any.servant-openapi3 ==2.0.1.6,
any.servant-server ==0.20,
any.servant-server ==0.20.2,
any.servant-static-th ==1.0.0.0,
servant-static-th -buildexample,
any.simple-sendfile ==0.2.32,
Expand Down Expand Up @@ -385,7 +389,7 @@ constraints: any.Cabal ==3.10.3.0,
any.transformers-compat ==0.7.2,
transformers-compat -five +five-three -four +generic-deriving +mtl -three -two,
any.tuples ==0.1.0.0,
any.typed-process ==0.2.11.1,
any.typed-process ==0.2.12.0,
any.typed-process-effectful ==1.0.0.2,
any.unicode-data ==0.6.0,
unicode-data -dev-has-icu,
Expand Down Expand Up @@ -417,7 +421,7 @@ constraints: any.Cabal ==3.10.3.0,
any.wai-extra ==3.1.15,
wai-extra -build-example,
any.wai-log ==0.4.0.1,
any.wai-logger ==2.4.0,
any.wai-logger ==2.4.1,
any.wai-middleware-heartbeat ==0.0.1.0,
any.warp ==3.3.31,
warp +allow-sendfilefd -network-bytestring -warp-debug -x509,
Expand Down
19 changes: 9 additions & 10 deletions flora.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ library
Data.Aeson.Orphans
Data.Positive
Data.Text.Display.Orphans
Data.Text.HTML
Data.Time.Orphans
Database.PostgreSQL.Simple.Orphans
Distribution.Orphans
Expand Down Expand Up @@ -145,7 +146,6 @@ library
, base ^>=4.18.2
, base16-bytestring
, base64
, blaze-builder
, bytestring
, Cabal-syntax
, colourista
Expand All @@ -154,6 +154,7 @@ library
, cryptohash-sha256
, cryptonite
, cryptonite-conduit
, dani-servant-lucid2
, deepseq
, deriving-aeson
, directory
Expand All @@ -167,7 +168,7 @@ library
, JuicyPixels
, log-base
, log-effectful
, lucid
, lucid2
, memory
, monad-time-effectful
, network
Expand All @@ -186,7 +187,6 @@ library
, resource-pool
, sel
, servant
, servant-lucid
, servant-server
, slugify
, souffle-haskell ==4.0.0
Expand Down Expand Up @@ -228,7 +228,6 @@ library flora-web
FloraWeb.Components.Alert
FloraWeb.Components.Button
FloraWeb.Components.CategoryCard
FloraWeb.Components.Footer
FloraWeb.Components.Header
FloraWeb.Components.Icons
FloraWeb.Components.MainSearchBar
Expand All @@ -242,6 +241,7 @@ library flora-web
FloraWeb.Components.VersionListHeader
FloraWeb.Embedded
FloraWeb.Links
FloraWeb.LiveReload
FloraWeb.Pages.Routes
FloraWeb.Pages.Routes.Admin
FloraWeb.Pages.Routes.Categories
Expand Down Expand Up @@ -290,6 +290,7 @@ library flora-web
, colourista
, containers
, cookie
, dani-servant-lucid2
, data-default
, deepseq
, deriving-aeson
Expand All @@ -299,16 +300,15 @@ library flora-web
, flora
, flora-jobs
, haddock-library
, htmx-lucid
, http-api-data
, http-client
, http-client-tls
, http-media
, http-types
, log-base
, log-effectful
, lucid
, lucid-alpine
, lucid-svg
, lucid2
, monad-time
, monad-time-effectful
, mtl
Expand All @@ -329,7 +329,7 @@ library flora-web
, servant
, servant-client
, servant-client-core
, servant-lucid
, servant-event-stream
, servant-openapi3
, servant-server
, text
Expand Down Expand Up @@ -379,7 +379,6 @@ library flora-jobs
, http-types
, log-base
, log-effectful
, lucid
, monad-time-effectful
, odd-jobs
, pg-entity
Expand Down Expand Up @@ -438,7 +437,7 @@ executable flora-cli
, flora-web
, log-base
, log-effectful
, lucid
, lucid2
, monad-time-effectful
, optics-core
, optparse-applicative
Expand Down
4 changes: 2 additions & 2 deletions src/core/Flora/Environment/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ data DeploymentEnv
deriving stock (Show, Eq, Generic, Enum, Bounded)

instance Display DeploymentEnv where
displayBuilder Production = "prod"
displayBuilder Development = "dev"
displayBuilder Production = "production"
displayBuilder Development = "development"
displayBuilder Test = "test"

data LoggingDestination
Expand Down
29 changes: 2 additions & 27 deletions src/core/Flora/Model/Release/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Flora.Model.Release.Types
( ReleaseId (..)
, TextHtml (..)
, TextHtml
, Release (..)
, ImportStatus (..)
, SupportedCompilers (..)
Expand All @@ -20,7 +20,6 @@ import Data.OpenApi.Schema (ToSchema)
import Data.Text (Text, unpack)
import Data.Text.Display
import Data.Text.Encoding (decodeUtf8, encodeUtf8)
import Data.Text.Lazy qualified as Text
import Data.Time (UTCTime)
import Data.Typeable (Typeable)
import Data.UUID (UUID)
Expand All @@ -37,8 +36,8 @@ import Distribution.SPDX.License qualified as SPDX
import Distribution.Types.Flag (PackageFlag)
import Distribution.Types.Version
import Distribution.Types.VersionRange (VersionRange)
import Lucid qualified

import Data.Text.HTML
import Distribution.Orphans ()
import Distribution.Orphans.BuildType ()
import Distribution.Orphans.CompilerFlavor ()
Expand All @@ -55,30 +54,6 @@ newtype ReleaseId = ReleaseId {getReleaseId :: UUID}
(Display)
via ShowInstance UUID

-- | a wrapper that attaches from and tofield instances
-- for a text db row for LucidHtml
newtype TextHtml = MkTextHtml (Lucid.Html ())
deriving stock (Show, Generic)

instance ToJSON TextHtml where
toJSON (MkTextHtml a) = String $ Text.toStrict $ Lucid.renderText a

instance FromJSON TextHtml where
parseJSON = withText "TextHtml" (pure . MkTextHtml . Lucid.toHtmlRaw @Text)

instance NFData TextHtml where
rnf a = seq a ()

instance Eq TextHtml where
(==) (MkTextHtml a) (MkTextHtml b) = Lucid.renderText a == Lucid.renderText b

--
instance FromField TextHtml where
fromField field bs = MkTextHtml . Lucid.toHtmlRaw @Text <$> fromField field bs

instance ToField TextHtml where
toField (MkTextHtml x) = toField $ Lucid.renderText x

data Release = Release
{ releaseId :: ReleaseId
, packageId :: PackageId
Expand Down
43 changes: 43 additions & 0 deletions src/datatypes/Data/Text/HTML.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module Data.Text.HTML
( TextHtml
, fromText
, toText
) where

import Control.DeepSeq
import Data.Aeson
import Data.Text
import Database.PostgreSQL.Simple.FromField (FromField (..))
import Database.PostgreSQL.Simple.ToField (ToField (..))
import GHC.Generics
import Lucid

-- | a wrapper that attaches from and tofield instances
-- for a text db row for LucidHtml
newtype TextHtml = MkTextHtml Text
deriving stock (Show, Generic)
deriving
(Eq, ToHtml)
via Text

instance ToJSON TextHtml where
toJSON (MkTextHtml a) = String a

instance FromJSON TextHtml where
parseJSON = withText "TextHtml" (pure . MkTextHtml)

instance NFData TextHtml where
rnf a = seq a ()

--
instance FromField TextHtml where
fromField field bs = MkTextHtml <$> fromField field bs

instance ToField TextHtml where
toField (MkTextHtml x) = toField x

fromText :: Text -> TextHtml
fromText = MkTextHtml

toText :: TextHtml -> Text
toText (MkTextHtml t) = t
22 changes: 7 additions & 15 deletions src/datatypes/Lucid/Orphans.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,28 @@

module Lucid.Orphans where

import Blaze.ByteString.Builder (Builder)
import Blaze.ByteString.Builder.Html.Utf8 qualified as Blaze
import Data.Time
import Distribution.Pretty qualified as Pretty
import Distribution.SPDX.License qualified as SPDX
import Distribution.Types.Version
import Lucid
import Lucid.Base
import Servant
import Servant.HTML.Lucid
import Servant.API.ContentTypes.Lucid

instance ToHtml Version where
toHtml = build . Blaze.fromHtmlEscapedString . Pretty.prettyShow
toHtmlRaw = build . Blaze.fromString . Pretty.prettyShow
toHtml = toHtml . Pretty.prettyShow
toHtmlRaw = toHtmlRaw . Pretty.prettyShow

instance ToHtml UTCTime where
toHtml = build . Blaze.fromHtmlEscapedString . show
toHtmlRaw = build . Blaze.fromString . show
toHtml = toHtml . show
toHtmlRaw = toHtmlRaw . show

instance ToHtml SPDX.License where
toHtml = build . Blaze.fromHtmlEscapedString . Pretty.prettyShow
toHtmlRaw = build . Blaze.fromString . Pretty.prettyShow
toHtml = toHtml . Pretty.prettyShow
toHtmlRaw = toHtmlRaw . Pretty.prettyShow

instance MimeUnrender HTML (Html ()) where
mimeUnrender _ bs = Right $ toHtmlRaw bs

instance MimeUnrender HTML NoContent where
mimeUnrender _ _ = Right NoContent

-- | Create an 'HtmlT' directly from a 'Builder'.
build :: Monad m => Builder -> HtmlT m ()
build b = HtmlT (return (const b, ()))
{-# INLINE build #-}
Loading

0 comments on commit 51f5f9c

Please sign in to comment.