From de07f76c92edc660ddaa5e043213c2f067dd3ce1 Mon Sep 17 00:00:00 2001 From: Ramzan Date: Sat, 4 Jul 2020 18:18:34 -0400 Subject: [PATCH] Implement an auto refresh function that calls fetchAll every minute if the user is online and logged in. Fixes #28. --- src/App.tsx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/App.tsx b/src/App.tsx index c77afae..41e0f3e 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -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(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) => {