]> cat aescling's git repositories - mastodon.git/blob - app/javascript/flavours/glitch/features/mutes/index.js
Merge branch 'master' into glitch-soc/merge-upstream
[mastodon.git] / app / javascript / flavours / glitch / features / mutes / 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 AccountContainer from 'flavours/glitch/containers/account_container';
10 import { fetchMutes, expandMutes } from 'flavours/glitch/actions/mutes';
11 import { defineMessages, injectIntl } from 'react-intl';
12 import ImmutablePureComponent from 'react-immutable-pure-component';
13
14 const messages = defineMessages({
15 heading: { id: 'column.mutes', defaultMessage: 'Muted users' },
16 });
17
18 const mapStateToProps = state => ({
19 accountIds: state.getIn(['user_lists', 'mutes', 'items']),
20 });
21
22 @connect(mapStateToProps)
23 @injectIntl
24 export default class Mutes 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(fetchMutes());
35 }
36
37 handleScroll = (e) => {
38 const { scrollTop, scrollHeight, clientHeight } = e.target;
39
40 if (scrollTop === scrollHeight - clientHeight) {
41 this.props.dispatch(expandMutes());
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>
56 <LoadingIndicator />
57 </Column>
58 );
59 }
60
61 return (
62 <Column name='mutes' icon='volume-off' heading={intl.formatMessage(messages.heading)}>
63 <ColumnBackButtonSlim />
64 <ScrollContainer scrollKey='mutes' shouldUpdateScroll={this.shouldUpdateScroll}>
65 <div className='scrollable mutes' onScroll={this.handleScroll}>
66 {accountIds.map(id =>
67 <AccountContainer key={id} id={id} />
68 )}
69 </div>
70 </ScrollContainer>
71 </Column>
72 );
73 }
74
75 }
This page took 0.074344 seconds and 4 git commands to generate.