Save previous stats to localStorage for faster loading
This commit is contained in:
parent
7d34cc9b88
commit
49cb7f0ebd
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue