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.
109 lines
3.3 KiB
109 lines
3.3 KiB
2 years ago
|
import { debounce } from 'lodash';
|
||
8 years ago
|
import PropTypes from 'prop-types';
|
||
2 years ago
|
import React from 'react';
|
||
|
import { Helmet } from 'react-helmet';
|
||
8 years ago
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||
8 years ago
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||
2 years ago
|
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
|
||
|
import { connect } from 'react-redux';
|
||
|
import { addColumn, removeColumn, moveColumn } from 'mastodon/actions/columns';
|
||
|
import { fetchFavouritedStatuses, expandFavouritedStatuses } from 'mastodon/actions/favourites';
|
||
|
import ColumnHeader from 'mastodon/components/column_header';
|
||
|
import StatusList from 'mastodon/components/status_list';
|
||
|
import Column from 'mastodon/features/ui/components/column';
|
||
8 years ago
|
|
||
|
const messages = defineMessages({
|
||
8 years ago
|
heading: { id: 'column.favourites', defaultMessage: 'Favourites' },
|
||
8 years ago
|
});
|
||
|
|
||
|
const mapStateToProps = state => ({
|
||
8 years ago
|
statusIds: state.getIn(['status_lists', 'favourites', 'items']),
|
||
7 years ago
|
isLoading: state.getIn(['status_lists', 'favourites', 'isLoading'], true),
|
||
7 years ago
|
hasMore: !!state.getIn(['status_lists', 'favourites', 'next']),
|
||
8 years ago
|
});
|
||
|
|
||
6 years ago
|
export default @connect(mapStateToProps)
|
||
8 years ago
|
@injectIntl
|
||
6 years ago
|
class Favourites extends ImmutablePureComponent {
|
||
8 years ago
|
|
||
8 years ago
|
static propTypes = {
|
||
|
dispatch: PropTypes.func.isRequired,
|
||
8 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,
|
||
7 years ago
|
isLoading: 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', {}));
|
||
|
}
|
||
2 years ago
|
};
|
||
7 years ago
|
|
||
|
handleMove = (dir) => {
|
||
|
const { columnId, dispatch } = this.props;
|
||
|
dispatch(moveColumn(columnId, dir));
|
||
2 years ago
|
};
|
||
7 years ago
|
|
||
|
handleHeaderClick = () => {
|
||
|
this.column.scrollTop();
|
||
2 years ago
|
};
|
||
7 years ago
|
|
||
|
setRef = c => {
|
||
|
this.column = c;
|
||
2 years ago
|
};
|
||
7 years ago
|
|
||
7 years ago
|
handleLoadMore = debounce(() => {
|
||
8 years ago
|
this.props.dispatch(expandFavouritedStatuses());
|
||
2 years ago
|
}, 300, { leading: true });
|
||
8 years ago
|
|
||
|
render () {
|
||
3 years ago
|
const { intl, statusIds, columnId, multiColumn, hasMore, isLoading } = this.props;
|
||
7 years ago
|
const pinned = !!columnId;
|
||
8 years ago
|
|
||
3 years ago
|
const emptyMessage = <FormattedMessage id='empty_column.favourited_statuses' defaultMessage="You don't have any favourite posts yet. When you favourite one, it will show up here." />;
|
||
6 years ago
|
|
||
8 years ago
|
return (
|
||
5 years ago
|
<Column bindToDocument={!multiColumn} ref={this.setRef} label={intl.formatMessage(messages.heading)}>
|
||
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
|
isLoading={isLoading}
|
||
7 years ago
|
onLoadMore={this.handleLoadMore}
|
||
6 years ago
|
emptyMessage={emptyMessage}
|
||
5 years ago
|
bindToDocument={!multiColumn}
|
||
7 years ago
|
/>
|
||
2 years ago
|
|
||
|
<Helmet>
|
||
|
<title>{intl.formatMessage(messages.heading)}</title>
|
||
2 years ago
|
<meta name='robots' content='noindex' />
|
||
2 years ago
|
</Helmet>
|
||
8 years ago
|
</Column>
|
||
|
);
|
||
|
}
|
||
|
|
||
8 years ago
|
}
|