diff options
| author | Christine Dodrill <me@christine.website> | 2017-05-20 23:30:47 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-05-20 23:30:47 -0700 |
| commit | 55f50910d96b94658b8d9d6bcaa09be5cc90bc05 (patch) | |
| tree | 07112ff8f7d2a67dbb5f99652181d4e205f877cb /frontend/src/BlogEntry.purs | |
| parent | 372573572913bebe24312b72f2c62d74bb8aba54 (diff) | |
| parent | e8f967619e02ebdd6daa5132012ea2382f34ce91 (diff) | |
| download | xesite-55f50910d96b94658b8d9d6bcaa09be5cc90bc05.tar.xz xesite-55f50910d96b94658b8d9d6bcaa09be5cc90bc05.zip | |
Merge pull request #4 from Xe/Xe/feat/server-side-rendering
Use server-side rendering, redo frontend with hack.css
Diffstat (limited to 'frontend/src/BlogEntry.purs')
| -rw-r--r-- | frontend/src/BlogEntry.purs | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/frontend/src/BlogEntry.purs b/frontend/src/BlogEntry.purs deleted file mode 100644 index 0a46976..0000000 --- a/frontend/src/BlogEntry.purs +++ /dev/null @@ -1,72 +0,0 @@ -module App.BlogEntry where - -import App.Utils (mdify) -import Control.Monad.Aff (attempt) -import DOM (DOM) -import Data.Argonaut (class DecodeJson, decodeJson, (.?)) -import Data.Either (Either(..), either) -import Data.Maybe (Maybe(..)) -import Network.HTTP.Affjax (AJAX, get) -import Prelude (bind, pure, show, ($), (<>), (<<<)) -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) - -type State = - { status :: String - , id :: Maybe Int - , post :: Post - , name :: String } - -data Post = Post - { title :: String - , body :: String - , date :: String } - -instance decodeJsonPost :: DecodeJson Post where - decodeJson json = do - obj <- decodeJson json - title <- obj .? "title" - body <- obj .? "body" - date <- obj .? "date" - pure $ Post { title: title, body: body, date: date } - -init :: State -init = - { status: "Loading..." - , post: Post - { title: "" - , body: "" - , date: "" } - , name: "" - , id: Nothing } - -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 = noEffects $ state { status = "", id = Just 1, post = post } -update RequestPost state = - { state: state - , effects: [ do - res <- attempt $ get ("/api/blog/post?name=" <> state.name) - let decode r = decodeJson r.response :: Either String Post - let post = either (Left <<< show) decode res - pure $ ReceivePost post - ] - } - -view :: State -> Html Action -view { id: id, status: status, post: (Post post) } = - case id of - Nothing -> div [] [] - (Just _) -> - div [ className "row" ] - [ h1 [] [ text status ] - , documentTitle [ title $ post.title <> " - Christine Dodrill" ] [] - , div [ className "col s8 offset-s2" ] - [ p [ id_ "blogpost", dangerouslySetInnerHTML $ mdify post.body ] [] ] - ] |
