Autoload blogposts on the blog page

This commit is contained in:
Cadey Ratio 2016-12-14 08:24:52 -08:00
parent 90f176019a
commit 449f76cb30
3 changed files with 6 additions and 27 deletions

View File

@ -80,5 +80,4 @@ view state =
div div
[] []
[ h1 [] [ text state.status ] [ h1 [] [ text state.status ]
, button [ onClick (const RequestPosts), id_ "requestbutton", className "hidden" ] [ text "Fetch posts" ]
, div [ className "row" ] $ map post state.posts ] , div [ className "row" ] $ map post state.posts ]

View File

@ -28,12 +28,17 @@ init =
, bistate: BlogIndex.init } , bistate: BlogIndex.init }
update :: Action -> State -> EffModel State Action (ajax :: AJAX, dom :: DOM) update :: Action -> State -> EffModel State Action (ajax :: AJAX, dom :: DOM)
update (PageView route) state = noEffects $ state { route = route } update (PageView route) state = routeEffects route $ state { route = route }
update (BIChild action) state = BlogIndex.update action state.bistate update (BIChild action) state = BlogIndex.update action state.bistate
# mapState (state { bistate = _ }) # mapState (state { bistate = _ })
# mapEffects BIChild # mapEffects BIChild
update (Child action) state = noEffects $ state { count = Counter.update action state.count } update (Child action) state = noEffects $ state { count = Counter.update action state.count }
routeEffects :: Route -> State -> EffModel State Action (dom :: DOM, ajax :: AJAX)
routeEffects BlogIndex state = { state: state
, effects: [ pure BlogIndex.RequestPosts ] } # mapEffects BIChild
routeEffects _ state = noEffects $ state
view :: State -> Html Action view :: State -> Html Action
view state = view state =
div div

View File

@ -14,30 +14,5 @@
</head> </head>
<body> <body>
<div id="app"></div> <div id="app"></div>
<script>
// Forgive me
function eventFire(el, etype){
if (el.fireEvent) {
el.fireEvent('on' + etype);
} else {
var evObj = document.createEvent('Events');
evObj.initEvent(etype, true, false);
el.dispatchEvent(evObj);
}
}
interval = setInterval(function() {
e = document.getElementById("requestbutton");
if(e != null) {
eventFire(e, "click");
} else {
console.log("Tried so hard been so far")
}
clearInterval(interval);
e.style.display = "none";
}, 250);
</script>
</body> </body>
</html> </html>