Browse Source

store results in state object so that they persist across unmounts

pull/1/head
wes 8 years ago
parent
commit
d6c594e747
  1. 13
      src/scripts/browse.tag
  2. 1
      src/scripts/post.tag

13
src/scripts/browse.tag

@ -5,10 +5,12 @@
onfilter={filterCategories} onfilter={filterCategories}
> >
</menu> </menu>
<loading if={loading}></loading>
<div <div
if={!loading}
style={cardStyle} style={cardStyle}
class="card content" class="card content"
each={result in results} each={result in opts.state.results}
> >
<div class="card-header"> <div class="card-header">
<a <a
@ -26,13 +28,14 @@
<script type="es6"> <script type="es6">
import './raw.tag'; import './raw.tag';
import './menu.tag'; import './menu.tag';
import './loading.tag';
import route from 'riot-route'; import route from 'riot-route';
import { default as RiotControl } from 'riotcontrol'; import { default as RiotControl } from 'riotcontrol';
var self = this; var self = this;
self.route = route; self.route = route;
self.results = self.opts.state.results; self.loading = false;
self.openPost = (id) => { self.openPost = (id) => {
return ((ev) => { return ((ev) => {
@ -48,12 +51,16 @@ self.cardStyle = {
self.filterCategories = (category) => { self.filterCategories = (category) => {
return ((ev) => { return ((ev) => {
self.update({"loading" : true});
ev.preventDefault(); ev.preventDefault();
self.route(`browse/${category}`); self.route(`browse/${category}`);
window.cached(`/blog/getbrowse/${category}/0`) window.cached(`/blog/getbrowse/${category}/0`)
.then((resp) => { return resp.json() }) .then((resp) => { return resp.json() })
.then((results) => { .then((results) => {
self.update({"results" : results}); self.opts.state.results = results;
self.update({
"loading" : false
});
}); });
}) })
} }

1
src/scripts/post.tag

@ -43,6 +43,7 @@
</div> </div>
</div> </div>
<script> <script>
import './loading.tag';
import './raw.tag'; import './raw.tag';
import './social.tag'; import './social.tag';
import './postcontrols.tag'; import './postcontrols.tag';

Loading…
Cancel
Save