about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/features/explore/statuses.js
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2022-10-09 11:48:06 +0200
committerGitHub <noreply@github.com>2022-10-09 11:48:06 +0200
commit44486db912ac6064419680dbc3dcd3843a02a144 (patch)
tree6e14c1298ee1ecfb4ba962f5752bedf13efd4d17 /app/javascript/flavours/glitch/features/explore/statuses.js
parent30f4268f325921c13f786e7f8d52d744ea542ef2 (diff)
parent7ba5905416ab9e62e429fdd21bc353aaeb312375 (diff)
Merge pull request #1859 from ClearlyClaire/glitch-soc/features/trends-tab
Port “Explore” tab to glitch-soc
Diffstat (limited to 'app/javascript/flavours/glitch/features/explore/statuses.js')
-rw-r--r--app/javascript/flavours/glitch/features/explore/statuses.js57
1 files changed, 57 insertions, 0 deletions
diff --git a/app/javascript/flavours/glitch/features/explore/statuses.js b/app/javascript/flavours/glitch/features/explore/statuses.js
new file mode 100644
index 000000000..fe08ce466
--- /dev/null
+++ b/app/javascript/flavours/glitch/features/explore/statuses.js
@@ -0,0 +1,57 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+import ImmutablePropTypes from 'react-immutable-proptypes';
+import StatusList from 'flavours/glitch/components/status_list';
+import { FormattedMessage } from 'react-intl';
+import { connect } from 'react-redux';
+import { fetchTrendingStatuses, expandTrendingStatuses } from 'flavours/glitch/actions/trends';
+import { debounce } from 'lodash';
+
+const mapStateToProps = state => ({
+  statusIds: state.getIn(['status_lists', 'trending', 'items']),
+  isLoading: state.getIn(['status_lists', 'trending', 'isLoading'], true),
+  hasMore: !!state.getIn(['status_lists', 'trending', 'next']),
+});
+
+export default @connect(mapStateToProps)
+class Statuses extends React.PureComponent {
+
+  static propTypes = {
+    statusIds: ImmutablePropTypes.list,
+    isLoading: PropTypes.bool,
+    hasMore: PropTypes.bool,
+    multiColumn: PropTypes.bool,
+    dispatch: PropTypes.func.isRequired,
+  };
+
+  componentDidMount () {
+    const { dispatch } = this.props;
+    dispatch(fetchTrendingStatuses());
+  }
+
+  handleLoadMore = debounce(() => {
+    const { dispatch } = this.props;
+    dispatch(expandTrendingStatuses());
+  }, 300, { leading: true })
+
+  render () {
+    const { isLoading, hasMore, statusIds, multiColumn } = this.props;
+
+    const emptyMessage = <FormattedMessage id='empty_column.explore_statuses' defaultMessage='Nothing is trending right now. Check back later!' />;
+
+    return (
+      <StatusList
+        trackScroll
+        statusIds={statusIds}
+        scrollKey='explore-statuses'
+        hasMore={hasMore}
+        isLoading={isLoading}
+        onLoadMore={this.handleLoadMore}
+        emptyMessage={emptyMessage}
+        bindToDocument={!multiColumn}
+        withCounters
+      />
+    );
+  }
+
+}