diff --git a/components/FetchedDataSectionList.js b/components/FetchedDataSectionList.js index 167870c..ab74572 100644 --- a/components/FetchedDataSectionList.js +++ b/components/FetchedDataSectionList.js @@ -20,6 +20,8 @@ type State = { machinesWatched: Array, }; +const minTimeBetweenRefresh = 60; + /** * Class used to create a basic list view using online json data. * Used by inheriting from it and redefining getters. @@ -32,6 +34,7 @@ export default class FetchedDataSectionList extends React.Component { - this.setState({refreshing: true}); - this.webDataManager.readData().then((fetchedData) => { - this.setState({ - fetchedData: fetchedData, - refreshing: false, - firstLoading: false - }); - this.webDataManager.showUpdateToast(this.getUpdateToastTranslations()[0], this.getUpdateToastTranslations()[1]); - }); + let canRefresh; + if (this.lastRefresh !== undefined) + canRefresh = (new Date().getTime() - this.lastRefresh.getTime())/1000 > minTimeBetweenRefresh; + else + canRefresh = true; + + if (canRefresh) { + this.setState({refreshing: true}); + this.webDataManager.readData() + .then((fetchedData) => { + this.setState({ + fetchedData: fetchedData, + refreshing: false, + firstLoading: false + }); + this.lastRefresh = new Date(); + }) + .catch((err) => { + this.setState({ + fetchedData: {}, + refreshing: false, + firstLoading: false + }); + this.webDataManager.showUpdateToast(this.getUpdateToastTranslations()[0], this.getUpdateToastTranslations()[1]); + }); + } + }; /** @@ -316,7 +337,8 @@ export default class FetchedDataSectionList extends React.Component + {this.hasTabs() ? {this.getTabbedView(dataset)} diff --git a/utils/WebDataManager.js b/utils/WebDataManager.js index 51f269d..5cf57f8 100644 --- a/utils/WebDataManager.js +++ b/utils/WebDataManager.js @@ -27,6 +27,7 @@ export default class WebDataManager { } catch (error) { console.log('Could not read FetchedData from server'); console.log(error); + throw new Error('Could not read FetchedData from server'); } this.lastDataFetched = fetchedData; return fetchedData;