forked from tanner/qotnews
order feed by reverse chronological
This commit is contained in:
parent
e63a1456a5
commit
4f90671cec
|
@ -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…
Reference in New Issue
Block a user