2017-05-02 20:04:16 -04:00
|
|
|
import React from 'react';
|
2017-01-16 07:27:58 -05:00
|
|
|
import { connect } from 'react-redux';
|
2017-04-21 14:05:35 -04:00
|
|
|
import PropTypes from 'prop-types';
|
2017-06-24 06:24:02 -04:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2017-11-17 22:11:18 -05:00
|
|
|
import { fetchFavouritedStatuses, expandFavouritedStatuses } from 'themes/glitch/actions/favourites';
|
|
|
|
import Column from 'themes/glitch/features/ui/components/column';
|
|
|
|
import ColumnHeader from 'themes/glitch/components/column_header';
|
|
|
|
import { addColumn, removeColumn, moveColumn } from 'themes/glitch/actions/columns';
|
|
|
|
import StatusList from 'themes/glitch/components/status_list';
|
2017-01-16 07:27:58 -05:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2017-05-02 20:04:16 -04:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2017-01-16 07:27:58 -05:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
2017-05-20 11:31:47 -04:00
|
|
|
heading: { id: 'column.favourites', defaultMessage: 'Favourites' },
|
2017-01-16 07:27:58 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
2017-06-24 06:24:02 -04:00
|
|
|
statusIds: state.getIn(['status_lists', 'favourites', 'items']),
|
2017-08-28 16:23:44 -04:00
|
|
|
hasMore: !!state.getIn(['status_lists', 'favourites', 'next']),
|
2017-01-16 07:27:58 -05:00
|
|
|
});
|
|
|
|
|
2017-06-23 13:36:54 -04:00
|
|
|
@connect(mapStateToProps)
|
|
|
|
@injectIntl
|
|
|
|
export default class Favourites extends ImmutablePureComponent {
|
2017-01-16 07:27:58 -05:00
|
|
|
|
2017-05-12 08:44:10 -04:00
|
|
|
static propTypes = {
|
|
|
|
dispatch: PropTypes.func.isRequired,
|
2017-06-24 06:24:02 -04:00
|
|
|
statusIds: ImmutablePropTypes.list.isRequired,
|
2017-05-12 08:44:10 -04:00
|
|
|
intl: PropTypes.object.isRequired,
|
2017-07-14 18:49:34 -04:00
|
|
|
columnId: PropTypes.string,
|
|
|
|
multiColumn: PropTypes.bool,
|
2017-08-28 16:23:44 -04:00
|
|
|
hasMore: PropTypes.bool,
|
2017-05-12 08:44:10 -04:00
|
|
|
};
|
2017-01-16 07:27:58 -05:00
|
|
|
|
|
|
|
componentWillMount () {
|
|
|
|
this.props.dispatch(fetchFavouritedStatuses());
|
2017-04-21 14:05:35 -04:00
|
|
|
}
|
2017-01-16 07:27:58 -05:00
|
|
|
|
2017-07-14 18:49:34 -04:00
|
|
|
handlePin = () => {
|
|
|
|
const { columnId, dispatch } = this.props;
|
|
|
|
|
|
|
|
if (columnId) {
|
|
|
|
dispatch(removeColumn(columnId));
|
|
|
|
} else {
|
|
|
|
dispatch(addColumn('FAVOURITES', {}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleMove = (dir) => {
|
|
|
|
const { columnId, dispatch } = this.props;
|
|
|
|
dispatch(moveColumn(columnId, dir));
|
|
|
|
}
|
|
|
|
|
|
|
|
handleHeaderClick = () => {
|
|
|
|
this.column.scrollTop();
|
|
|
|
}
|
|
|
|
|
|
|
|
setRef = c => {
|
|
|
|
this.column = c;
|
|
|
|
}
|
|
|
|
|
2017-05-12 08:44:10 -04:00
|
|
|
handleScrollToBottom = () => {
|
2017-01-16 07:27:58 -05:00
|
|
|
this.props.dispatch(expandFavouritedStatuses());
|
2017-04-21 14:05:35 -04:00
|
|
|
}
|
2017-01-16 07:27:58 -05:00
|
|
|
|
|
|
|
render () {
|
2017-08-28 16:23:44 -04:00
|
|
|
const { intl, statusIds, columnId, multiColumn, hasMore } = this.props;
|
2017-07-14 18:49:34 -04:00
|
|
|
const pinned = !!columnId;
|
2017-01-16 07:27:58 -05:00
|
|
|
|
|
|
|
return (
|
2017-08-06 15:27:47 -04:00
|
|
|
<Column ref={this.setRef} name='favourites'>
|
2017-07-14 18:49:34 -04:00
|
|
|
<ColumnHeader
|
|
|
|
icon='star'
|
|
|
|
title={intl.formatMessage(messages.heading)}
|
|
|
|
onPin={this.handlePin}
|
|
|
|
onMove={this.handleMove}
|
|
|
|
onClick={this.handleHeaderClick}
|
|
|
|
pinned={pinned}
|
|
|
|
multiColumn={multiColumn}
|
2017-09-06 11:32:15 -04:00
|
|
|
showBackButton
|
2017-07-14 18:49:34 -04:00
|
|
|
/>
|
|
|
|
|
|
|
|
<StatusList
|
|
|
|
trackScroll={!pinned}
|
|
|
|
statusIds={statusIds}
|
|
|
|
scrollKey={`favourited_statuses-${columnId}`}
|
2017-08-28 16:23:44 -04:00
|
|
|
hasMore={hasMore}
|
2017-07-14 18:49:34 -04:00
|
|
|
onScrollToBottom={this.handleScrollToBottom}
|
|
|
|
/>
|
2017-01-16 07:27:58 -05:00
|
|
|
</Column>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-04-21 14:05:35 -04:00
|
|
|
}
|