Browse Source

store results in state object so that they persist across unmounts

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

Loading…
Cancel
Save