]> cat aescling's git repositories - mastodon.git/blob - app/javascript/flavours/glitch/features/follow_requests/index.js
Merge branch 'master' into glitch-soc/merge-upstream
[mastodon.git] / app / javascript / flavours / glitch / features / follow_requests / index.js
1 import React from 'react';
2 import { connect } from 'react-redux';
3 import PropTypes from 'prop-types';
4 import ImmutablePropTypes from 'react-immutable-proptypes';
5 import LoadingIndicator from 'flavours/glitch/components/loading_indicator';
6 import { ScrollContainer } from 'react-router-scroll-4';
7 import Column from 'flavours/glitch/features/ui/components/column';
8 import ColumnBackButtonSlim from 'flavours/glitch/components/column_back_button_slim';
9 import AccountAuthorizeContainer from './containers/account_authorize_container';
10 import { fetchFollowRequests, expandFollowRequests } from 'flavours/glitch/actions/accounts';
11 import { defineMessages, injectIntl } from 'react-intl';
12 import ImmutablePureComponent from 'react-immutable-pure-component';
13
14 const messages = defineMessages({
15 heading: { id: 'column.follow_requests', defaultMessage: 'Follow requests' },
16 });
17
18 const mapStateToProps = state => ({
19 accountIds: state.getIn(['user_lists', 'follow_requests', 'items']),
20 });
21
22 @connect(mapStateToProps)
23 @injectIntl
24 export default class FollowRequests extends ImmutablePureComponent {
25
26 static propTypes = {
27 params: PropTypes.object.isRequired,
28 dispatch: PropTypes.func.isRequired,
29 accountIds: ImmutablePropTypes.list,
30 intl: PropTypes.object.isRequired,
31 };
32
33 componentWillMount () {
34 this.props.dispatch(fetchFollowRequests());
35 }
36
37 handleScroll = (e) => {
38 const { scrollTop, scrollHeight, clientHeight } = e.target;
39
40 if (scrollTop === scrollHeight - clientHeight) {
41 this.props.dispatch(expandFollowRequests());
42 }
43 }
44
45 shouldUpdateScroll = (prevRouterProps, { location }) => {
46 if ((((prevRouterProps || {}).location || {}).state || {}).mastodonModalOpen) return false;
47 return !(location.state && location.state.mastodonModalOpen);
48 }
49
50 render () {
51 const { intl, accountIds } = this.props;
52
53 if (!accountIds) {
54 return (
55 <Column name='follow-requests'>
56 <LoadingIndicator />
57 </Column>
58 );
59 }
60
61 return (
62 <Column name='follow-requests' icon='users' heading={intl.formatMessage(messages.heading)}>
63 <ColumnBackButtonSlim />
64
65 <ScrollContainer scrollKey='follow_requests' shouldUpdateScroll={this.shouldUpdateScroll}>
66 <div className='scrollable' onScroll={this.handleScroll}>
67 {accountIds.map(id =>
68 <AccountAuthorizeContainer key={id} id={id} />
69 )}
70 </div>
71 </ScrollContainer>
72 </Column>
73 );
74 }
75
76 }
This page took 0.116312 seconds and 4 git commands to generate.