use named record constructors

This commit is contained in:
Jon Schoning 2020-06-15 09:45:33 -05:00 committed by Yann Esposito (Yogsototh)
parent a0e107e7c0
commit 9bee6a718b
Signed by untrusted user who does not match committer: yogsototh
GPG key ID: 7B19A4C650D59646
3 changed files with 30 additions and 19 deletions

View file

@ -30,18 +30,26 @@ getAddViewR = do
bookmarkFormUrl :: Handler BookmarkForm
bookmarkFormUrl = do
Entity _ user <- requireAuth
BookmarkForm
<$> (lookupGetParam "url" >>= pure . fromMaybe "")
<*> (lookupGetParam "title")
<*> (lookupGetParam "description" >>= pure . fmap Textarea)
<*> (lookupGetParam "tags")
<*> (lookupGetParam "private" >>= pure . fmap parseChk <&> (<|> Just (userPrivateDefault user)))
<*> (lookupGetParam "toread" >>= pure . fmap parseChk)
<*> pure Nothing
<*> pure Nothing
<*> pure Nothing
<*> pure Nothing
<*> pure Nothing
url <- lookupGetParam "url" >>= pure . fromMaybe ""
title <- lookupGetParam "title"
description <- lookupGetParam "description" >>= pure . fmap Textarea
tags <- lookupGetParam "tags"
private <- lookupGetParam "private" >>= pure . fmap parseChk <&> (<|> Just (userPrivateDefault user))
toread <- lookupGetParam "toread" >>= pure . fmap parseChk
pure $
BookmarkForm
{ _url = url
, _title = title
, _description = description
, _tags = tags
, _private = private
, _toread = toread
, _bid = Nothing
, _slug = Nothing
, _selected = Nothing
, _time = Nothing
, _archiveUrl = Nothing
}
where
parseChk s = s == "yes" || s == "on"

View file

@ -69,7 +69,7 @@ getAddNoteViewR :: UserNameP -> Handler Html
getAddNoteViewR unamep@(UserNameP uname) = do
userId <- requireAuthId
let renderEl = "note" :: Text
note <- liftIO $ Entity (NoteKey 0) <$> _toNote userId (NoteForm Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing)
note <- liftIO $ Entity (NoteKey 0) <$> _toNote userId emptyNoteForm
defaultLayout $ do
$(widgetFile "note")
toWidgetBody [julius|
@ -129,6 +129,9 @@ instance ToJSON NoteForm where toJSON = A.genericToJSON gNoteFormOptions
gNoteFormOptions :: A.Options
gNoteFormOptions = A.defaultOptions { A.fieldLabelModifier = drop 1 }
emptyNoteForm :: NoteForm
emptyNoteForm = NoteForm Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing
_toNote :: UserId -> NoteForm -> IO Note
_toNote userId NoteForm {..} = do
time <- liftIO getCurrentTime

View file

@ -694,12 +694,12 @@ _toBookmark userId BookmarkForm {..} = do
{ bookmarkUserId = userId
, bookmarkSlug = slug
, bookmarkHref = _url
, bookmarkDescription = (fromMaybe "" _title)
, bookmarkExtended = (maybe "" unTextarea _description)
, bookmarkTime = (fromMaybe time (fmap unUTCTimeStr _time))
, bookmarkShared = (maybe True not _private)
, bookmarkToRead = (fromMaybe False _toread)
, bookmarkSelected = (fromMaybe False _selected)
, bookmarkDescription = fromMaybe "" _title
, bookmarkExtended = maybe "" unTextarea _description
, bookmarkTime = fromMaybe time (fmap unUTCTimeStr _time)
, bookmarkShared = maybe True not _private
, bookmarkToRead = fromMaybe False _toread
, bookmarkSelected = fromMaybe False _selected
, bookmarkArchiveHref = _archiveUrl
}