Skip to content

Commit

Permalink
Improve Paragraphs breadcrumbs (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreytroeglazov authored Jul 19, 2024
1 parent aea4fa8 commit 6b9fc0d
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 7 deletions.
4 changes: 4 additions & 0 deletions Web/Controller/ParagraphCtas.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ instance Controller ParagraphCtasController where

-- Get all landing pages, so we can select the one we want to link to.
landingPages <- query @LandingPage |> fetch
landingPage <- fetch paragraphCta.landingPageId

render NewView { .. }

Expand All @@ -23,6 +24,7 @@ instance Controller ParagraphCtasController where

-- Get all landing pages, so we can select the one we want to link to.
landingPages <- query @LandingPage |> fetch
landingPage <- fetch paragraphCta.landingPageId

render EditView { .. }

Expand All @@ -33,6 +35,7 @@ instance Controller ParagraphCtasController where
|> ifValid \case
Left paragraphCta -> do
landingPages <- query @LandingPage |> fetch
landingPage <- fetch paragraphCta.landingPageId
render EditView { .. }
Right paragraphCta -> do
paragraphCta <- paragraphCta |> updateRecord
Expand All @@ -46,6 +49,7 @@ instance Controller ParagraphCtasController where
|> ifValid \case
Left paragraphCta -> do
landingPages <- query @LandingPage |> fetch
landingPage <- fetch paragraphCta.landingPageId
render NewView { .. }
Right paragraphCta -> do
paragraphCta <- paragraphCta |> createRecord
Expand Down
4 changes: 4 additions & 0 deletions Web/Controller/ParagraphHeroImages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ instance Controller ParagraphHeroImagesController where
|> set #weight weight

let formStatus = FormStatusNotSubmitted
landingPage <- fetch paragraphHeroImage.landingPageId

render NewView { .. }

action EditParagraphHeroImageAction { paragraphHeroImageId } = do
paragraphHeroImage <- fetch paragraphHeroImageId
-- Get from the session, if the form was submitted successfully.
formStatus <- getAndClearFormStatus
landingPage <- fetch paragraphHeroImage.landingPageId

render EditView { .. }

action UpdateParagraphHeroImageAction { paragraphHeroImageId } = do
Expand Down Expand Up @@ -56,6 +59,7 @@ createOrUpdateParagraphHeroImageAction maybeParagraphHeroImageId = do
>>= ifValid \case
Left paragraphHeroImage -> do
setFormStatus FormStatusError
landingPage <- fetch paragraphHeroImage.landingPageId
if isJust maybeParagraphHeroImageId
then render EditView { .. }
else render NewView { .. }
Expand Down
3 changes: 3 additions & 0 deletions Web/Controller/ParagraphQuotes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ instance Controller ParagraphQuotesController where
|> set #weight weight

let formStatus = FormStatusNotSubmitted
landingPage <- fetch paragraphQuote.landingPageId

render NewView { .. }

action EditParagraphQuoteAction { paragraphQuoteId } = do
paragraphQuote <- fetch paragraphQuoteId
landingPage <- fetch paragraphQuote.landingPageId
-- Get from the session, if the form was submitted successfully.
formStatus <- getAndClearFormStatus
render EditView { .. }
Expand Down Expand Up @@ -57,6 +59,7 @@ createOrUpdateParagraphQuoteAction maybeParagraphQuoteId = do
>>= ifValid \case
Left paragraphQuote -> do
setFormStatus FormStatusError
landingPage <- fetch paragraphQuote.landingPageId
if isJust maybeParagraphQuoteId
then render EditView { .. }
else render NewView { .. }
Expand Down
5 changes: 4 additions & 1 deletion Web/View/ParagraphCtas/Edit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Web.Element.ElementWrap
data EditView = EditView
{ paragraphCta :: ParagraphCta
, landingPages :: [LandingPage]
, landingPage :: LandingPage
}

instance View EditView where
Expand All @@ -17,7 +18,9 @@ instance View EditView where
|]
where
breadcrumb = renderBreadcrumb
[ breadcrumbText "Edit Cta"
[ breadcrumbText "Landing Page"
, breadcrumbLink (cs landingPage.title) (EditLandingPageAction landingPage.id)
, breadcrumbText "Edit CTA"
]

renderForm :: ParagraphCta -> [LandingPage] -> Html
Expand Down
5 changes: 4 additions & 1 deletion Web/View/ParagraphCtas/New.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Web.Element.ElementWrap
data NewView = NewView
{ paragraphCta :: ParagraphCta
, landingPages :: [LandingPage]
, landingPage :: LandingPage
}

instance View NewView where
Expand All @@ -16,7 +17,9 @@ instance View NewView where
|]
where
breadcrumb = renderBreadcrumb
[ breadcrumbText "New Cta"
[ breadcrumbText "Landing Page"
, breadcrumbLink (cs landingPage.title) (EditLandingPageAction landingPage.id)
, breadcrumbText "New CTA"
]

renderForm :: ParagraphCta -> [LandingPage] -> Html
Expand Down
5 changes: 4 additions & 1 deletion Web/View/ParagraphHeroImages/Edit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Web.View.ParagraphHeroImages.Form
data EditView = EditView
{ paragraphHeroImage :: ParagraphHeroImage
, formStatus :: FormStatus
, landingPage :: LandingPage
}

instance View EditView where
Expand All @@ -15,5 +16,7 @@ instance View EditView where
|]
where
breadcrumb = renderBreadcrumb
[ breadcrumbText "Edit Hero Image"
[ breadcrumbText "Landing Page"
, breadcrumbLink (cs landingPage.title) (EditLandingPageAction landingPage.id)
, breadcrumbText "Edit Hero Image"
]
5 changes: 4 additions & 1 deletion Web/View/ParagraphHeroImages/New.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Web.View.ParagraphHeroImages.Form
data NewView = NewView
{ paragraphHeroImage :: ParagraphHeroImage
, formStatus :: FormStatus
, landingPage :: LandingPage
}

instance View NewView where
Expand All @@ -16,6 +17,8 @@ instance View NewView where
|]
where
breadcrumb = renderBreadcrumb
[ breadcrumbText "New Hero Image"
[ breadcrumbText "Landing Page"
, breadcrumbLink (cs landingPage.title) (EditLandingPageAction landingPage.id)
, breadcrumbText "New Hero Image"
]

7 changes: 5 additions & 2 deletions Web/View/ParagraphQuotes/Edit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Web.View.ParagraphQuotes.Form
data EditView = EditView
{ paragraphQuote :: ParagraphQuote
, formStatus :: FormStatus
, landingPage :: LandingPage
}

instance View EditView where
Expand All @@ -15,5 +16,7 @@ instance View EditView where
|]
where
breadcrumb = renderBreadcrumb
[ breadcrumbText "Edit Quote"
]
[ breadcrumbText "Landing Page"
, breadcrumbLink (cs landingPage.title) (EditLandingPageAction landingPage.id)
, breadcrumbText "Edit Quote"
]
5 changes: 4 additions & 1 deletion Web/View/ParagraphQuotes/New.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Web.View.ParagraphQuotes.Form
data NewView = NewView
{ paragraphQuote :: ParagraphQuote
, formStatus :: FormStatus
, landingPage :: LandingPage
}

instance View NewView where
Expand All @@ -16,6 +17,8 @@ instance View NewView where
|]
where
breadcrumb = renderBreadcrumb
[ breadcrumbText "New Quote"
[ breadcrumbText "Landing Page"
, breadcrumbLink (cs landingPage.title) (EditLandingPageAction landingPage.id)
, breadcrumbText "New Quote"
]

0 comments on commit 6b9fc0d

Please sign in to comment.