Save previous stats to localStorage for faster loading

This commit is contained in:
MICHAEL JACKSON 2017-08-26 17:45:58 -07:00
parent 7d34cc9b88
commit 49cb7f0ebd
1 changed files with 11 additions and 0 deletions

View File

@ -50,6 +50,17 @@ class Layout extends React.Component {
fetch('/_stats/last-month')
.then(res => res.json())
.then(stats => this.setState({ stats }))
if (window.localStorage) {
const savedStats = window.localStorage.savedStats
if (savedStats)
this.setState({ stats: JSON.parse(savedStats) })
window.onbeforeunload = () => {
localStorage.savedStats = JSON.stringify(this.state.stats)
}
}
}
componentDidUpdate(prevProps) {