Implement an auto refresh function that calls fetchAll every minute

if the user is online and logged in.

Fixes #28.
master
Ramzan 2020-07-04 18:18:34 -04:00 committed by Tom Hacohen
parent b394484f3c
commit de07f76c92
1 changed files with 10 additions and 0 deletions

View File

@ -178,6 +178,7 @@ class App extends React.PureComponent {
this.toggleDrawer = this.toggleDrawer.bind(this);
this.closeDrawer = this.closeDrawer.bind(this);
this.refresh = this.refresh.bind(this);
this.autoRefresh = this.autoRefresh.bind(this);
}
public render() {
@ -279,6 +280,15 @@ class App extends React.PureComponent {
private refresh() {
store.store.dispatch<any>(actions.fetchAll(this.props.credentials, this.props.entries));
}
private autoRefresh() {
if (navigator.onLine && this.props.credentials) { this.refresh() }
}
componentDidMount() {
const interval = 60 * 1000;
setInterval(this.autoRefresh, interval);
}
}
const mapStateToProps = (state: store.StoreState) => {