From fe06fc8880a0ac5524ce771f7565d5da654d2a55 Mon Sep 17 00:00:00 2001 From: nek0 Date: Mon, 14 Oct 2019 20:11:45 +0200 Subject: [PATCH] make code reusable --- src/View/User.hs | 52 +++++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/src/View/User.hs b/src/View/User.hs index be8f33e..c1e7ee7 100644 --- a/src/View/User.hs +++ b/src/View/User.hs @@ -77,14 +77,42 @@ userOverviewPage l10n locale method ud pos = scaffold l10n locale (initPage $ $ H.toHtml $ translate "Logout" case method of MT.PrimaryPass -> - userSettingsPointer + userSettingsPointer l10n locale MT.SecondaryPass -> - productList + productList pos MT.ChallengeResponse -> do - userSettingsPointer - productList + userSettingsPointer l10n locale + productList pos where translate = localize l10n locale . gettext + +userSettingsPointer + :: L10n + -> Locale + -> H.Html +userSettingsPointer l10n locale = + H.a H.! HA.href ("/" <> (fromString $ show $ linkURI $ userManageLink)) $ + H.toHtml $ translate "Manage user settings" + where + translate = localize l10n locale . gettext + +productList + :: [MT.ProductShortOverview] + -> H.Html +productList pos = + H.p $ + H.ul H.! HA.class_ "product_list" $ + mapM_ + (\(MT.ProductShortOverview pid ident _ _ _ avatarid) -> do + H.li H.! HA.class_ "product" H.!? + (isJust avatarid + , productBgStyle (fromString $ show $ fromJust avatarid) + ) $ + H.a H.! HA.href ("#" <> fromString (show pid)) $ + H.toHtml ident + ) + pos + where productBgStyle aid = HA.style $ mconcat [ "background-image: url(#" <> aid <> ");" -- FILLME , "backgronud-color: blue;" @@ -94,22 +122,6 @@ userOverviewPage l10n locale method ud pos = scaffold l10n locale (initPage $ , " 1px 0 1px black," , " 0 -1px 1px black;" ] - userSettingsPointer = - H.a H.! HA.href ("/" <> (fromString $ show $ linkURI $ userManageLink)) $ - H.toHtml $ translate "Manage user settings" - productList = - H.p $ - H.ul H.! HA.class_ "product_list" $ - mapM_ - (\(MT.ProductShortOverview pid ident _ _ _ avatarid) -> do - H.li H.! HA.class_ "product" H.!? - (isJust avatarid - , productBgStyle (fromString $ show $ fromJust avatarid) - ) $ - H.a H.! HA.href ("#" <> fromString (show pid)) $ - H.toHtml ident - ) - pos userNewPage :: L10n