aboutsummaryrefslogtreecommitdiff
path: root/frontend
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2016-12-18 08:51:32 -0800
committerChristine Dodrill <me@christine.website>2016-12-18 08:51:32 -0800
commitdba3ae46f8cbf9eca60e324447e7715744c2130b (patch)
tree71c7bcfd26d9e66fe3ef9683bccc6f674523cb87 /frontend
parent0315c0b72158a2ae3cc827c6922a4dbcbef3a002 (diff)
downloadxesite-dba3ae46f8cbf9eca60e324447e7715744c2130b.tar.xz
xesite-dba3ae46f8cbf9eca60e324447e7715744c2130b.zip
view my resume
Diffstat (limited to 'frontend')
-rw-r--r--frontend/src/BlogIndex.purs4
-rw-r--r--frontend/src/Layout.purs21
-rw-r--r--frontend/src/Resume.purs66
-rw-r--r--frontend/src/Routes.purs2
4 files changed, 85 insertions, 8 deletions
diff --git a/frontend/src/BlogIndex.purs b/frontend/src/BlogIndex.purs
index 8083575..1b41dbf 100644
--- a/frontend/src/BlogIndex.purs
+++ b/frontend/src/BlogIndex.purs
@@ -82,5 +82,5 @@ view state =
[]
[ h1 [] [ text "Posts" ]
, documentTitle [ title "Posts - Christine Dodrill" ] []
- , p [] [ text state.status ]
- , div [ className "row" ] $ map post state.posts ]
+ , div [ className "row" ] $ map post state.posts
+ , p [] [ text state.status ] ]
diff --git a/frontend/src/Layout.purs b/frontend/src/Layout.purs
index 1b810aa..da5b55e 100644
--- a/frontend/src/Layout.purs
+++ b/frontend/src/Layout.purs
@@ -3,6 +3,7 @@ module App.Layout where
import App.BlogEntry as BlogEntry
import App.BlogIndex as BlogIndex
import App.Counter as Counter
+import App.Resume as Resume
import App.Routes (Route(..))
import Control.Monad.RWS (state)
import DOM (DOM)
@@ -20,20 +21,23 @@ data Action
= Child (Counter.Action)
| BIChild (BlogIndex.Action)
| BEChild (BlogEntry.Action)
+ | REChild (Resume.Action)
| PageView Route
type State =
{ route :: Route
, count :: Counter.State
, bistate :: BlogIndex.State
- , bestate :: BlogEntry.State }
+ , bestate :: BlogEntry.State
+ , restate :: Resume.State }
init :: State
init =
{ route: NotFound
, count: Counter.init
, bistate: BlogIndex.init
- , bestate: BlogEntry.init }
+ , bestate: BlogEntry.init
+ , restate: Resume.init }
update :: Action -> State -> EffModel State Action (ajax :: AJAX, dom :: DOM)
update (PageView route) state = routeEffects route $ state { route = route }
@@ -43,14 +47,19 @@ update (BIChild action) state = BlogIndex.update action state.bistate
update (BEChild action) state = BlogEntry.update action state.bestate
# mapState (state { bestate = _ })
# mapEffects BEChild
+update (REChild action) state = Resume.update action state.restate
+ # mapState ( state { restate = _ })
+ # mapEffects REChild
update (Child action) state = noEffects $ state { count = Counter.update action state.count }
update _ state = noEffects $ state
routeEffects :: Route -> State -> EffModel State Action (dom :: DOM, ajax :: AJAX)
-routeEffects BlogIndex state = { state: state
+routeEffects (BlogIndex) state = { state: state
, effects: [ pure BlogIndex.RequestPosts ] } # mapEffects BIChild
-routeEffects (BlogPost page) state = { state: state { bestate = BlogEntry.init { name = page } }
- , effects: [ pure BlogEntry.RequestPost ] } # mapEffects BEChild
+routeEffects (Resume) state = { state: state
+ , effects: [ pure Resume.RequestResume ] } # mapEffects REChild
+routeEffects (BlogPost page') state = { state: state { bestate = BlogEntry.init { name = page' } }
+ , effects: [ pure BlogEntry.RequestPost ] } # mapEffects BEChild
routeEffects _ state = noEffects $ state
view :: State -> Html Action
@@ -162,7 +171,7 @@ index =
page :: Route -> State -> Html Action
page NotFound _ = h1 [] [ text "not found" ]
page Home _ = index
-page Resume state = h1 [] [ text "Christine Dodrill" ]
+page Resume state = map REChild $ Resume.view state.restate
page BlogIndex state = map BIChild $ BlogIndex.view state.bistate
page (BlogPost _) state = map BEChild $ BlogEntry.view state.bestate
page ContactPage _ = contact
diff --git a/frontend/src/Resume.purs b/frontend/src/Resume.purs
new file mode 100644
index 0000000..8a23d02
--- /dev/null
+++ b/frontend/src/Resume.purs
@@ -0,0 +1,66 @@
+module App.Resume 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 (Unit, bind, pure, show, unit, ($), (<>), (<<<))
+import Pux (noEffects, EffModel)
+import Pux.DocumentTitle (documentTitle)
+import Pux.Html (Html, a, div, h1, p, text)
+import Pux.Html.Attributes (href, dangerouslySetInnerHTML, className, id_, title)
+
+data Action = RequestResume
+ | ReceiveResume (Either String Resume)
+
+type State =
+ { status :: String
+ , err :: String
+ , resume :: Maybe Resume }
+
+data Resume = Resume
+ { body :: String }
+
+instance decodeJsonResume :: DecodeJson Resume where
+ decodeJson json = do
+ obj <- decodeJson json
+ body <- obj .? "body"
+ pure $ Resume { body: body }
+
+init :: State
+init =
+ { status: "Loading..."
+ , err: ""
+ , resume: Nothing }
+
+update :: Action -> State -> EffModel State Action (ajax :: AJAX, dom :: DOM)
+update (ReceiveResume (Left err)) state =
+ noEffects $ state { resume = Nothing, status = "Error in fetching resume, please use the plain text link below.", err = err }
+update (ReceiveResume (Right body)) state =
+ noEffects $ state { status = "", err = "", resume = Just body }
+ where
+ got' = Just unit
+update RequestResume state =
+ { state: state
+ , effects: [ do
+ res <- attempt $ get "/api/resume"
+ let decode r = decodeJson r.response :: Either String Resume
+ let resume = either (Left <<< show) decode res
+ pure $ ReceiveResume resume
+ ]
+ }
+
+view :: State -> Html Action
+view { status: status, err: err, resume: resume } =
+ case resume of
+ Nothing -> div [] [ text status, p [] [ text err ] ]
+ (Just (Resume resume')) ->
+ div [ className "row" ]
+ [ documentTitle [ title "Resume - Christine Dodrill" ] []
+ , div [ className "col s8 offset-s2" ]
+ [ p [ className "browser-default", dangerouslySetInnerHTML $ mdify resume'.body ] []
+ , a [ href "/static/resume/resume.md" ] [ text "Plain-text version of this resume here" ], text "." ]
+ ]
diff --git a/frontend/src/Routes.purs b/frontend/src/Routes.purs
index 886e774..7076898 100644
--- a/frontend/src/Routes.purs
+++ b/frontend/src/Routes.purs
@@ -27,3 +27,5 @@ match url = fromMaybe NotFound $ router url $
BlogPost <$> (lit "blog" *> str) <* end
<|>
ContactPage <$ lit "contact" <* end
+ <|>
+ Resume <$ lit "resume" <* end