about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/features/home_timeline/index.js
diff options
context:
space:
mode:
authorDavid Yip <yipdw@member.fsf.org>2018-01-18 22:00:11 -0600
committerGitHub <noreply@github.com>2018-01-18 22:00:11 -0600
commit26ecee79bfd4cb4f97a91e57e7a8b3fb7de3d82a (patch)
tree08e5da13297f842a0416898307685bdd020865b6 /app/javascript/flavours/glitch/features/home_timeline/index.js
parentae369bceb35a4d9ee964fecb19d4c0ab83a05080 (diff)
parent3896cd5d79d8b46473b935b00caf31ef943fb21d (diff)
Merge pull request #332 from glitch-soc/merge-upstream
Merge in home feed regeneration changes from upstream
Diffstat (limited to 'app/javascript/flavours/glitch/features/home_timeline/index.js')
-rw-r--r--app/javascript/flavours/glitch/features/home_timeline/index.js37
1 files changed, 36 insertions, 1 deletions
diff --git a/app/javascript/flavours/glitch/features/home_timeline/index.js b/app/javascript/flavours/glitch/features/home_timeline/index.js
index 2dfec6bbe..c20c0244a 100644
--- a/app/javascript/flavours/glitch/features/home_timeline/index.js
+++ b/app/javascript/flavours/glitch/features/home_timeline/index.js
@@ -1,6 +1,6 @@
 import React from 'react';
 import { connect } from 'react-redux';
-import { expandHomeTimeline } from 'flavours/glitch/actions/timelines';
+import { expandHomeTimeline, refreshHomeTimeline } from 'flavours/glitch/actions/timelines';
 import PropTypes from 'prop-types';
 import StatusListContainer from 'flavours/glitch/features/ui/containers/status_list_container';
 import Column from 'flavours/glitch/components/column';
@@ -16,6 +16,7 @@ const messages = defineMessages({
 
 const mapStateToProps = state => ({
   hasUnread: state.getIn(['timelines', 'home', 'unread']) > 0,
+  isPartial: state.getIn(['timelines', 'home', 'isPartial'], false),
 });
 
 @connect(mapStateToProps)
@@ -26,6 +27,7 @@ export default class HomeTimeline extends React.PureComponent {
     dispatch: PropTypes.func.isRequired,
     intl: PropTypes.object.isRequired,
     hasUnread: PropTypes.bool,
+    isPartial: PropTypes.bool,
     columnId: PropTypes.string,
     multiColumn: PropTypes.bool,
   };
@@ -57,6 +59,39 @@ export default class HomeTimeline extends React.PureComponent {
     this.props.dispatch(expandHomeTimeline());
   }
 
+  componentDidMount () {
+    this._checkIfReloadNeeded(false, this.props.isPartial);
+  }
+
+  componentDidUpdate (prevProps) {
+    this._checkIfReloadNeeded(prevProps.isPartial, this.props.isPartial);
+  }
+
+  componentWillUnmount () {
+    this._stopPolling();
+  }
+
+  _checkIfReloadNeeded (wasPartial, isPartial) {
+    const { dispatch } = this.props;
+
+    if (wasPartial === isPartial) {
+      return;
+    } else if (!wasPartial && isPartial) {
+      this.polling = setInterval(() => {
+        dispatch(refreshHomeTimeline());
+      }, 3000);
+    } else if (wasPartial && !isPartial) {
+      this._stopPolling();
+    }
+  }
+
+  _stopPolling () {
+    if (this.polling) {
+      clearInterval(this.polling);
+      this.polling = null;
+    }
+  }
+
   render () {
     const { intl, hasUnread, columnId, multiColumn } = this.props;
     const pinned = !!columnId;