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/BlogIndex.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/BlogIndex.purs')
| -rw-r--r-- | frontend/src/BlogIndex.purs | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/frontend/src/BlogIndex.purs b/frontend/src/BlogIndex.purs deleted file mode 100644 index 1b41dbf..0000000 --- a/frontend/src/BlogIndex.purs +++ /dev/null @@ -1,86 +0,0 @@ -module App.BlogIndex where - -import Control.Monad.Aff (attempt) -import DOM (DOM) -import Data.Argonaut (class DecodeJson, decodeJson, (.?)) -import Data.Either (Either(Left, Right), either) -import Network.HTTP.Affjax (AJAX, get) -import Prelude (($), bind, map, const, show, (<>), pure, (<<<)) -import Pux (EffModel, noEffects) -import Pux.DocumentTitle (documentTitle) -import Pux.Html (Html, br, div, h1, ol, li, button, text, span, p) -import Pux.Html.Attributes (className, id_, key, title) -import Pux.Html.Events (onClick) -import Pux.Router (link) - -data Action = RequestPosts - | ReceivePosts (Either String Posts) - -type State = - { posts :: Posts - , status :: String } - -data Post = Post - { title :: String - , link :: String - , summary :: String - , date :: String } - -type Posts = Array Post - -instance decodeJsonPost :: DecodeJson Post where - decodeJson json = do - obj <- decodeJson json - title <- obj .? "title" - link <- obj .? "link" - summ <- obj .? "summary" - date <- obj .? "date" - pure $ Post { title: title, link: link, summary: summ, date: date } - -init :: State -init = - { posts: [] - , status: "" } - -update :: Action -> State -> EffModel State Action (ajax :: AJAX, dom :: DOM) -update (ReceivePosts (Left err)) state = - noEffects $ state { status = ("error: " <> err) } -update (ReceivePosts (Right posts)) state = - noEffects $ state { posts = posts, status = "" } -update RequestPosts state = - { state: state { status = "Loading..." } - , effects: [ do - res <- attempt $ get "/api/blog/posts" - let decode r = decodeJson r.response :: Either String Posts - let posts = either (Left <<< show) decode res - pure $ ReceivePosts posts - ] - } - -post :: Post -> Html Action -post (Post state) = - div - [ className "col s6" ] - [ div - [ className "card pink lighten-5" ] - [ div - [ className "card-content black-text" ] - [ span [ className "card-title" ] [ text state.title ] - , br [] [] - , p [] [ text ("Posted on: " <> state.date) ] - , span [] [ text state.summary ] - ] - , div - [ className "card-action pink lighten-5" ] - [ link state.link [] [ text "Read More" ] ] - ] - ] - -view :: State -> Html Action -view state = - div - [] - [ h1 [] [ text "Posts" ] - , documentTitle [ title "Posts - Christine Dodrill" ] [] - , div [ className "row" ] $ map post state.posts - , p [] [ text state.status ] ] |
