frontend: make mdify return rendered html
This commit is contained in:
parent
62ffa5f008
commit
e1a6482dc6
|
@ -8,18 +8,16 @@ import Data.Either (Either(..), either)
|
|||
import Data.Maybe (Maybe(..))
|
||||
import Network.HTTP.Affjax (AJAX, get)
|
||||
import Prelude (bind, pure, show, ($), (<>), (<<<))
|
||||
import Pux (EffModel, noEffects)
|
||||
import Pux (noEffects, EffModel)
|
||||
import Pux.DocumentTitle (documentTitle)
|
||||
import Pux.Html (Html, div, h1, p, text)
|
||||
import Pux.Html.Attributes (dangerouslySetInnerHTML, className, id_, title)
|
||||
|
||||
data Action = RequestPost
|
||||
| ReceivePost (Either String Post)
|
||||
| RenderPost
|
||||
|
||||
type State =
|
||||
{ status :: String
|
||||
, hack :: String
|
||||
, id :: Maybe Int
|
||||
, post :: Post
|
||||
, name :: String }
|
||||
|
@ -40,7 +38,6 @@ instance decodeJsonPost :: DecodeJson Post where
|
|||
init :: State
|
||||
init =
|
||||
{ status: "Loading..."
|
||||
, hack: ""
|
||||
, post: Post
|
||||
{ title: ""
|
||||
, body: ""
|
||||
|
@ -51,10 +48,7 @@ init =
|
|||
update :: Action -> State -> EffModel State Action (ajax :: AJAX, dom :: DOM)
|
||||
update (ReceivePost (Left err)) state =
|
||||
noEffects $ state { id = Nothing, status = err }
|
||||
update (ReceivePost (Right post)) state =
|
||||
{ state: state { status = "", id = Just 1, post = post }
|
||||
, effects: [ pure $ RenderPost ]
|
||||
}
|
||||
update (ReceivePost (Right post)) state = noEffects $ state { status = "", id = Just 1, post = post }
|
||||
update RequestPost state =
|
||||
{ state: state
|
||||
, effects: [ do
|
||||
|
@ -64,8 +58,6 @@ update RequestPost state =
|
|||
pure $ ReceivePost post
|
||||
]
|
||||
}
|
||||
update RenderPost state =
|
||||
noEffects $ state { hack = mdify "blogpost" }
|
||||
|
||||
view :: State -> Html Action
|
||||
view { id: id, status: status, post: (Post post) } =
|
||||
|
@ -76,5 +68,5 @@ view { id: id, status: status, post: (Post post) } =
|
|||
[ h1 [] [ text status ]
|
||||
, documentTitle [ title $ post.title <> " - Christine Dodrill" ] []
|
||||
, div [ className "col s8 offset-s2" ]
|
||||
[ p [ id_ "blogpost", dangerouslySetInnerHTML post.body ] [] ]
|
||||
[ p [ id_ "blogpost", dangerouslySetInnerHTML $ mdify post.body ] [] ]
|
||||
]
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
// Module App.BlogEntry
|
||||
|
||||
exports.mdify = function(id) {
|
||||
exports.mdify = function(corpus) {
|
||||
var converter = new showdown.Converter()
|
||||
elem = document.getElementById(id);
|
||||
md = elem.innerHTML;
|
||||
elem.innerHTML = converter.makeHtml(md);
|
||||
return "done :)";
|
||||
return converter.makeHtml(corpus);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue