chinwagsocial/app/javascript/mastodon/features/favourited_statuses/index.js

63 lines
1.9 KiB
JavaScript
Raw Normal View History

import React from 'react';
2017-01-16 23:27:58 +11:00
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
2017-01-16 23:27:58 +11:00
import ImmutablePropTypes from 'react-immutable-proptypes';
import LoadingIndicator from '../../components/loading_indicator';
import { fetchFavouritedStatuses, expandFavouritedStatuses } from '../../actions/favourites';
import Column from '../ui/components/column';
import StatusList from '../../components/status_list';
import ColumnBackButtonSlim from '../../components/column_back_button_slim';
2017-01-16 23:27:58 +11:00
import { defineMessages, injectIntl } from 'react-intl';
import ImmutablePureComponent from 'react-immutable-pure-component';
2017-01-16 23:27:58 +11:00
const messages = defineMessages({
heading: { id: 'column.favourites', defaultMessage: 'Favourites' }
});
const mapStateToProps = state => ({
statusIds: state.getIn(['status_lists', 'favourites', 'items']),
loaded: state.getIn(['status_lists', 'favourites', 'loaded']),
me: state.getIn(['meta', 'me'])
});
class Favourites extends ImmutablePureComponent {
2017-01-16 23:27:58 +11:00
static propTypes = {
dispatch: PropTypes.func.isRequired,
statusIds: ImmutablePropTypes.list.isRequired,
loaded: PropTypes.bool,
intl: PropTypes.object.isRequired,
me: PropTypes.number.isRequired
};
2017-01-16 23:27:58 +11:00
componentWillMount () {
this.props.dispatch(fetchFavouritedStatuses());
}
2017-01-16 23:27:58 +11:00
handleScrollToBottom = () => {
2017-01-16 23:27:58 +11:00
this.props.dispatch(expandFavouritedStatuses());
}
2017-01-16 23:27:58 +11:00
render () {
const { statusIds, loaded, intl, me } = this.props;
if (!loaded) {
return (
<Column>
<LoadingIndicator />
</Column>
);
}
return (
<Column icon='star' heading={intl.formatMessage(messages.heading)}>
<ColumnBackButtonSlim />
<StatusList {...this.props} scrollKey='favourited_statuses' onScrollToBottom={this.handleScrollToBottom} />
2017-01-16 23:27:58 +11:00
</Column>
);
}
}
2017-01-16 23:27:58 +11:00
export default connect(mapStateToProps)(injectIntl(Favourites));