1
0
mirror of https://github.com/funamitech/mastodon synced 2024-12-23 02:58:34 +09:00
YuruToot/app/javascript/mastodon/features/favourited_statuses/index.jsx

113 lines
3.3 KiB
React
Raw Normal View History

import PropTypes from 'prop-types';
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
import { Helmet } from 'react-helmet';
import ImmutablePropTypes from 'react-immutable-proptypes';
import ImmutablePureComponent from 'react-immutable-pure-component';
import { connect } from 'react-redux';
import { debounce } from 'lodash';
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';
import { getStatusList } from 'mastodon/selectors';
2017-01-16 21:27:58 +09:00
const messages = defineMessages({
heading: { id: 'column.favourites', defaultMessage: 'Favorites' },
2017-01-16 21:27:58 +09:00
});
const mapStateToProps = state => ({
statusIds: getStatusList(state, 'favourites'),
isLoading: state.getIn(['status_lists', 'favourites', 'isLoading'], true),
hasMore: !!state.getIn(['status_lists', 'favourites', 'next']),
2017-01-16 21:27:58 +09:00
});
2018-09-15 00:59:48 +09:00
class Favourites extends ImmutablePureComponent {
2017-01-16 21:27:58 +09:00
static propTypes = {
dispatch: PropTypes.func.isRequired,
statusIds: ImmutablePropTypes.list.isRequired,
intl: PropTypes.object.isRequired,
columnId: PropTypes.string,
multiColumn: PropTypes.bool,
hasMore: PropTypes.bool,
isLoading: PropTypes.bool,
};
2017-01-16 21:27:58 +09:00
UNSAFE_componentWillMount () {
2017-01-16 21:27:58 +09:00
this.props.dispatch(fetchFavouritedStatuses());
}
2017-01-16 21:27:58 +09:00
handlePin = () => {
const { columnId, dispatch } = this.props;
if (columnId) {
dispatch(removeColumn(columnId));
} else {
dispatch(addColumn('FAVOURITES', {}));
}
2023-01-30 09:45:35 +09:00
};
handleMove = (dir) => {
const { columnId, dispatch } = this.props;
dispatch(moveColumn(columnId, dir));
2023-01-30 09:45:35 +09:00
};
handleHeaderClick = () => {
this.column.scrollTop();
2023-01-30 09:45:35 +09:00
};
setRef = c => {
this.column = c;
2023-01-30 09:45:35 +09:00
};
handleLoadMore = debounce(() => {
2017-01-16 21:27:58 +09:00
this.props.dispatch(expandFavouritedStatuses());
2023-01-30 09:45:35 +09:00
}, 300, { leading: true });
2017-01-16 21:27:58 +09:00
render () {
const { intl, statusIds, columnId, multiColumn, hasMore, isLoading } = this.props;
const pinned = !!columnId;
2017-01-16 21:27:58 +09:00
const emptyMessage = <FormattedMessage id='empty_column.favourited_statuses' defaultMessage="You don't have any favorite posts yet. When you favorite one, it will show up here." />;
2017-01-16 21:27:58 +09:00
return (
<Column bindToDocument={!multiColumn} ref={this.setRef} label={intl.formatMessage(messages.heading)}>
<ColumnHeader
icon='star'
title={intl.formatMessage(messages.heading)}
onPin={this.handlePin}
onMove={this.handleMove}
onClick={this.handleHeaderClick}
pinned={pinned}
multiColumn={multiColumn}
/>
<StatusList
trackScroll={!pinned}
statusIds={statusIds}
scrollKey={`favourited_statuses-${columnId}`}
hasMore={hasMore}
isLoading={isLoading}
onLoadMore={this.handleLoadMore}
emptyMessage={emptyMessage}
bindToDocument={!multiColumn}
/>
<Helmet>
<title>{intl.formatMessage(messages.heading)}</title>
<meta name='robots' content='noindex' />
</Helmet>
2017-01-16 21:27:58 +09:00
</Column>
);
}
}
export default connect(mapStateToProps)(injectIntl(Favourites));