2017-05-02 19:04:16 -05:00
|
|
|
import React from 'react';
|
2017-01-16 06:27:58 -06:00
|
|
|
import { connect } from 'react-redux';
|
2017-04-21 13:05:35 -05:00
|
|
|
import PropTypes from 'prop-types';
|
2017-06-24 05:24:02 -05:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2017-12-04 01:26:40 -06:00
|
|
|
import { fetchFavouritedStatuses, expandFavouritedStatuses } from 'flavours/glitch/actions/favourites';
|
|
|
|
import Column from 'flavours/glitch/features/ui/components/column';
|
|
|
|
import ColumnHeader from 'flavours/glitch/components/column_header';
|
|
|
|
import { addColumn, removeColumn, moveColumn } from 'flavours/glitch/actions/columns';
|
|
|
|
import StatusList from 'flavours/glitch/components/status_list';
|
2017-01-16 06:27:58 -06:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2017-05-02 19:04:16 -05:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2018-01-09 08:46:35 -06:00
|
|
|
import { debounce } from 'lodash';
|
2017-01-16 06:27:58 -06:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
2017-05-20 10:31:47 -05:00
|
|
|
heading: { id: 'column.favourites', defaultMessage: 'Favourites' },
|
2017-01-16 06:27:58 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
2017-06-24 05:24:02 -05:00
|
|
|
statusIds: state.getIn(['status_lists', 'favourites', 'items']),
|
2018-01-09 08:46:35 -06:00
|
|
|
isLoading: state.getIn(['status_lists', 'favourites', 'isLoading'], true),
|
2017-08-28 15:23:44 -05:00
|
|
|
hasMore: !!state.getIn(['status_lists', 'favourites', 'next']),
|
2017-01-16 06:27:58 -06:00
|
|
|
});
|
|
|
|
|
2017-06-23 12:36:54 -05:00
|
|
|
@connect(mapStateToProps)
|
|
|
|
@injectIntl
|
|
|
|
export default class Favourites extends ImmutablePureComponent {
|
2017-01-16 06:27:58 -06:00
|
|
|
|
2017-05-12 07:44:10 -05:00
|
|
|
static propTypes = {
|
|
|
|
dispatch: PropTypes.func.isRequired,
|
2017-06-24 05:24:02 -05:00
|
|
|
statusIds: ImmutablePropTypes.list.isRequired,
|
2017-05-12 07:44:10 -05:00
|
|
|
intl: PropTypes.object.isRequired,
|
2017-07-14 17:49:34 -05:00
|
|
|
columnId: PropTypes.string,
|
|
|
|
multiColumn: PropTypes.bool,
|
2017-08-28 15:23:44 -05:00
|
|
|
hasMore: PropTypes.bool,
|
2018-01-09 08:46:35 -06:00
|
|
|
isLoading: PropTypes.bool,
|
2017-05-12 07:44:10 -05:00
|
|
|
};
|
2017-01-16 06:27:58 -06:00
|
|
|
|
|
|
|
componentWillMount () {
|
|
|
|
this.props.dispatch(fetchFavouritedStatuses());
|
2017-04-21 13:05:35 -05:00
|
|
|
}
|
2017-01-16 06:27:58 -06:00
|
|
|
|
2017-07-14 17:49:34 -05: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;
|
|
|
|
}
|
|
|
|
|
2018-05-27 10:46:48 -05:00
|
|
|
handleLoadMore = debounce(() => {
|
2017-01-16 06:27:58 -06:00
|
|
|
this.props.dispatch(expandFavouritedStatuses());
|
2018-01-09 08:46:35 -06:00
|
|
|
}, 300, { leading: true })
|
2017-01-16 06:27:58 -06:00
|
|
|
|
|
|
|
render () {
|
2018-01-09 08:46:35 -06:00
|
|
|
const { intl, statusIds, columnId, multiColumn, hasMore, isLoading } = this.props;
|
2017-07-14 17:49:34 -05:00
|
|
|
const pinned = !!columnId;
|
2017-01-16 06:27:58 -06:00
|
|
|
|
|
|
|
return (
|
2018-08-28 05:01:04 -05:00
|
|
|
<Column ref={this.setRef} name='favourites' label={intl.formatMessage(messages.heading)}>
|
2017-07-14 17:49:34 -05: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 10:32:15 -05:00
|
|
|
showBackButton
|
2017-07-14 17:49:34 -05:00
|
|
|
/>
|
|
|
|
|
|
|
|
<StatusList
|
|
|
|
trackScroll={!pinned}
|
|
|
|
statusIds={statusIds}
|
|
|
|
scrollKey={`favourited_statuses-${columnId}`}
|
2017-08-28 15:23:44 -05:00
|
|
|
hasMore={hasMore}
|
2018-01-09 08:46:35 -06:00
|
|
|
isLoading={isLoading}
|
2018-05-27 10:46:48 -05:00
|
|
|
onLoadMore={this.handleLoadMore}
|
2017-07-14 17:49:34 -05:00
|
|
|
/>
|
2017-01-16 06:27:58 -06:00
|
|
|
</Column>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-04-21 13:05:35 -05:00
|
|
|
}
|