use named record constructors
This commit is contained in:
parent
4a574287b9
commit
f6096921f8
|
@ -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"
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
12
src/Model.hs
12
src/Model.hs
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue