-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
738892c
commit 3e3be79
Showing
16 changed files
with
265 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
module Web.Controller.ParagraphHeroImages where | ||
|
||
import Web.Controller.Prelude | ||
import Web.View.ParagraphHeroImages.New | ||
import Web.View.ParagraphHeroImages.Edit | ||
|
||
instance Controller ParagraphHeroImagesController where | ||
action NewParagraphHeroImageAction { .. } = do | ||
weight <- getParagraphsCount landingPageId | ||
let paragraphHeroImage = newRecord | ||
|> set #landingPageId landingPageId | ||
|> set #weight weight | ||
|
||
let formStatus = FormStatusNotSubmitted | ||
|
||
render NewView { .. } | ||
|
||
action EditParagraphHeroImageAction { paragraphHeroImageId } = do | ||
paragraphHeroImage <- fetch paragraphHeroImageId | ||
-- Get from the session, if the form was submitted successfully. | ||
formStatus <- getAndClearFormStatus | ||
render EditView { .. } | ||
|
||
action UpdateParagraphHeroImageAction { paragraphHeroImageId } = do | ||
let uploadImage = uploadToStorageWithOptions $ def | ||
{ preprocess = applyImageMagick "jpg" ["-resize", "1024x1024^", "-gravity", "north", "-extent", "1024x1024", "-quality", "85%", "-strip"] } | ||
|
||
formStatus <- getAndClearFormStatus | ||
|
||
paragraphHeroImage <- fetch paragraphHeroImageId | ||
paragraphHeroImage | ||
|> uploadImage #imageUrl | ||
>>= buildParagraphHeroImage | ||
>>= ifValid \case | ||
Left paragraphHeroImage -> do | ||
setFormStatus FormStatusError | ||
render EditView { .. } | ||
Right paragraphHeroImage -> do | ||
paragraphHeroImage <- paragraphHeroImage |> updateRecord | ||
setSuccessMessage "Hero Image updated" | ||
-- We don't setFormStatus, since we redirect to a new page. | ||
redirectTo EditLandingPageAction { landingPageId = paragraphHeroImage.landingPageId } | ||
|
||
action CreateParagraphHeroImageAction = do | ||
let uploadImage = uploadToStorageWithOptions $ def | ||
{ preprocess = applyImageMagick "jpg" ["-resize", "1024x1024^", "-gravity", "north", "-extent", "1024x1024", "-quality", "85%", "-strip"] } | ||
|
||
let paragraphHeroImage = newRecord @ParagraphHeroImage | ||
let formStatus = FormStatusNotSubmitted | ||
|
||
paragraphHeroImage | ||
|> uploadImage #imageUrl | ||
>>= buildParagraphHeroImage | ||
>>= ifValid \case | ||
Left paragraphHeroImage -> do | ||
setFormStatus FormStatusError | ||
render NewView { .. } | ||
Right paragraphHeroImage -> do | ||
paragraphHeroImage <- paragraphHeroImage |> createRecord | ||
setSuccessMessage "Hero Image created" | ||
-- We don't setFormStatus, since we redirect to a new page. | ||
redirectTo EditLandingPageAction { landingPageId = paragraphHeroImage.landingPageId } | ||
|
||
action DeleteParagraphHeroImageAction { paragraphHeroImageId } = do | ||
paragraphHeroImage <- fetch paragraphHeroImageId | ||
deleteRecord paragraphHeroImage | ||
setSuccessMessage "Hero Image deleted" | ||
redirectTo EditLandingPageAction { landingPageId = paragraphHeroImage.landingPageId } | ||
|
||
buildParagraphHeroImage paragraphHeroImage = paragraphHeroImage | ||
|> fill @["landingPageId", "weight", "title", "subtitle"] | ||
|> validateField #title nonEmpty | ||
|> validateField #imageUrl nonEmpty | ||
|> return | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
module Web.Element.HeroImage where | ||
|
||
import Web.View.Prelude | ||
|
||
import Application.Helper.Icons | ||
import Web.Element.ElementWrap | ||
import Web.Element.Types | ||
|
||
|
||
render :: RenderHeroImage -> Html | ||
render record@RenderHeroImage {title, subtitle, imageUrl} = | ||
titleWrapped | ||
++ subTitleWrapped | ||
|> wrapVerticalSpacing AlignNone | ||
|> renderImageAndContent (pathTo $ RenderImageStyleAction 400 200 imageUrl signed) | ||
where | ||
-- Sign the image URL to prevent tampering. | ||
signed = signImageUrl imageUrl 400 200 | ||
|
||
titleWrapped = cs subtitle | ||
|> wrapTextResponsiveFontSize TextSizeSm | ||
|
||
subTitleWrapped = cs subtitle | ||
|> wrapTextResponsiveFontSize TextSizeSm | ||
|
||
|
||
renderImageAndContent :: Text -> Html -> Html | ||
renderImageAndContent imageUrl items = | ||
-- We use grid and row/col start to position both the image and the text on the same cell. | ||
[hsx| | ||
<div class="flex flex-col sm:grid sm:grid-rows-1 md:grid-cols-2 gap-2 md:gap-8 lg:gap-10 overflow-hidden bg-gray-50"> | ||
|
||
<div class="w-full grid grid-rows-1"> | ||
<figure class="row-start-1 col-start-1 child-object-cover h-full"> | ||
{image} | ||
</figure> | ||
</div> | ||
<div class="pt-5 pb-8 px-5 lg:py-8 lg:max-w-lg my-auto"> | ||
{items} | ||
</div> | ||
</div> | ||
|] | ||
where | ||
image = [hsx|<img src={imageUrl} class="w-full h-full" />|] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.