You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
2.6 KiB
95 lines
2.6 KiB
8 years ago
|
import React from 'react';
|
||
8 years ago
|
import { connect } from 'react-redux';
|
||
8 years ago
|
import PropTypes from 'prop-types';
|
||
7 years ago
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||
7 years ago
|
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';
|
||
8 years ago
|
import { defineMessages, injectIntl } from 'react-intl';
|
||
8 years ago
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||
8 years ago
|
|
||
|
const messages = defineMessages({
|
||
8 years ago
|
heading: { id: 'column.favourites', defaultMessage: 'Favourites' },
|
||
8 years ago
|
});
|
||
|
|
||
|
const mapStateToProps = state => ({
|
||
7 years ago
|
statusIds: state.getIn(['status_lists', 'favourites', 'items']),
|
||
7 years ago
|
hasMore: !!state.getIn(['status_lists', 'favourites', 'next']),
|
||
8 years ago
|
});
|
||
|
|
||
8 years ago
|
@connect(mapStateToProps)
|
||
|
@injectIntl
|
||
|
export default class Favourites extends ImmutablePureComponent {
|
||
8 years ago
|
|
||
8 years ago
|
static propTypes = {
|
||
|
dispatch: PropTypes.func.isRequired,
|
||
7 years ago
|
statusIds: ImmutablePropTypes.list.isRequired,
|
||
8 years ago
|
intl: PropTypes.object.isRequired,
|
||
7 years ago
|
columnId: PropTypes.string,
|
||
|
multiColumn: PropTypes.bool,
|
||
7 years ago
|
hasMore: PropTypes.bool,
|
||
8 years ago
|
};
|
||
8 years ago
|
|
||
|
componentWillMount () {
|
||
|
this.props.dispatch(fetchFavouritedStatuses());
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
7 years ago
|
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;
|
||
|
}
|
||
|
|
||
8 years ago
|
handleScrollToBottom = () => {
|
||
8 years ago
|
this.props.dispatch(expandFavouritedStatuses());
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
|
render () {
|
||
7 years ago
|
const { intl, statusIds, columnId, multiColumn, hasMore } = this.props;
|
||
7 years ago
|
const pinned = !!columnId;
|
||
8 years ago
|
|
||
|
return (
|
||
7 years ago
|
<Column ref={this.setRef} name='favourites'>
|
||
7 years ago
|
<ColumnHeader
|
||
|
icon='star'
|
||
|
title={intl.formatMessage(messages.heading)}
|
||
|
onPin={this.handlePin}
|
||
|
onMove={this.handleMove}
|
||
|
onClick={this.handleHeaderClick}
|
||
|
pinned={pinned}
|
||
|
multiColumn={multiColumn}
|
||
7 years ago
|
showBackButton
|
||
7 years ago
|
/>
|
||
|
|
||
|
<StatusList
|
||
|
trackScroll={!pinned}
|
||
|
statusIds={statusIds}
|
||
|
scrollKey={`favourited_statuses-${columnId}`}
|
||
7 years ago
|
hasMore={hasMore}
|
||
7 years ago
|
onScrollToBottom={this.handleScrollToBottom}
|
||
|
/>
|
||
8 years ago
|
</Column>
|
||
|
);
|
||
|
}
|
||
|
|
||
8 years ago
|
}
|