order feed by reverse chronological

master
Jason Schwarzenberger 4 years ago
parent e63a1456a5
commit 4f90671cec
  1. 23
      webclient/src/Feed.js

@ -22,20 +22,25 @@ class Feed extends React.Component {
const updated = !this.state.stories || this.state.stories[0].id !== result.stories[0].id; const updated = !this.state.stories || this.state.stories[0].id !== result.stories[0].id;
console.log('updated:', updated); console.log('updated:', updated);
this.setState({ stories: result.stories }); const { stories } = result;
localStorage.setItem('stories', JSON.stringify(result.stories)); if (stories) {
stories.sort((a, b) => b.date - a.date);
}
this.setState({ stories });
localStorage.setItem('stories', JSON.stringify(stories));
if (updated) { if (updated) {
localForage.clear(); localForage.clear();
result.stories.forEach((x, i) => { stories.forEach((x, i) => {
fetch('/api/' + x.id) fetch('/api/' + x.id)
.then(res => res.json()) .then(res => res.json())
.then(result => { .then(({ story }) => {
localForage.setItem(x.id, result.story) localForage.setItem(x.id, story)
.then(console.log('preloaded', x.id, x.title)); .then(console.log('preloaded', x.id, x.title));
this.props.updateCache(x.id, result.story); this.props.updateCache(x.id, story);
}, error => {} }, error => { }
); );
}); });
} }
}, },
@ -73,7 +78,7 @@ class Feed extends React.Component {
</div> </div>
)} )}
</div> </div>
: :
<p>loading...</p> <p>loading...</p>
} }
</div> </div>

Loading…
Cancel
Save