Skip to content

Commit c8fb8af

Browse files
committed
added 20s timeout for refreshing the app
1 parent 3c52eb0 commit c8fb8af

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/gists/screens/gistComments.screen.js

+18-6
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,15 @@ const CommentDate = styled.Text`
4949
// `;
5050

5151
class GistCommentsScreen extends React.Component {
52-
state = {
53-
comment: '',
52+
constructor() {
53+
super();
54+
this.state = {
55+
comment: '',
56+
};
57+
this.timeout = null;
5458
}
5559
componentDidMount() {
56-
this.props.fetchComments(this.props.navigation.getParam('gistData').id);
60+
this.fetchComments();
5761
}
5862

5963
// onEndReachedThreshold = () => {
@@ -70,10 +74,18 @@ class GistCommentsScreen extends React.Component {
7074
.then(() => {
7175
this.setState({ comment: '' });
7276
this.props.fetchComments(this.props.navigation.getParam('gistData').id);
73-
// .then(() => {})
74-
// .catch(error => console.log('error---------', error));
7577
})
76-
.catch(error => console.log('&&&&&&&&&&&&&&&&&&&&&', error));
78+
.catch(console.log);
79+
}
80+
81+
fetchComments = () => {
82+
this.props.fetchComments(this.props.navigation.getParam('gistData').id);
83+
this.registerForDataFetch();
84+
}
85+
86+
registerForDataFetch = () => {
87+
clearTimeout(this.timeout);
88+
this.timeout = setTimeout(this.fetchComments, 20000);
7789
}
7890

7991
renderItem = ({ item }) => {

0 commit comments

Comments
 (0)