diff --git a/src/Handler/Home.hs b/src/Handler/Home.hs index 0f069b2..dad5af9 100644 --- a/src/Handler/Home.hs +++ b/src/Handler/Home.hs @@ -25,15 +25,33 @@ along with this program. If not, see . module Handler.Home where import Import +import Helpers + +title :: Text +title = "DiscussMormonism.com Link Fixer" + +linkForm :: Form Text +linkForm = renderDivs $ + areq urlField "Old URL" Nothing getHomeR :: Handler Html -getHomeR = defaultLayout $ do - setTitle "Welcome To Yesod!" - $(widgetFile "homepage") +getHomeR = do + (widget, enctype) <- generateFormPost linkForm + defaultLayout $ do + setTitle $ toHtml title + $(widgetFile "homepage") postHomeR :: Handler Html -postHomeR = defaultLayout $ do - setTitle "Welcome To Yesod!" - $(widgetFile "homepage") +postHomeR = do + ((result, _), _) <- runFormPost linkForm + case result of + FormSuccess l -> case updateLink l of + Just l' -> redirect l' + Nothing -> do + setMessage "Invalid link" + redirect HomeR + _ -> do + setMessage "Something went wrong" + redirect HomeR --jl diff --git a/templates/homepage.hamlet b/templates/homepage.hamlet index 49193fe..b323aa9 100644 --- a/templates/homepage.hamlet +++ b/templates/homepage.hamlet @@ -1,5 +1,11 @@ -
-
-
-

- DiscussMormonism.com Link Fixer +