2017-05-02 17:04:16 -07:00
|
|
|
import React from 'react';
|
2016-12-03 12:04:57 -08:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2017-04-21 11:05:35 -07:00
|
|
|
import PropTypes from 'prop-types';
|
2017-12-03 23:26:40 -08:00
|
|
|
import StatusContainer from 'flavours/glitch/containers/status_container';
|
2017-05-02 17:04:16 -07:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2017-08-28 13:23:44 -07:00
|
|
|
import ScrollableList from './scrollable_list';
|
2018-01-18 08:25:37 -08:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2016-08-24 08:56:44 -07:00
|
|
|
|
2017-06-23 10:36:54 -07:00
|
|
|
export default class StatusList extends ImmutablePureComponent {
|
2017-04-21 11:05:35 -07:00
|
|
|
|
2017-05-12 05:44:10 -07:00
|
|
|
static propTypes = {
|
|
|
|
scrollKey: PropTypes.string.isRequired,
|
|
|
|
statusIds: ImmutablePropTypes.list.isRequired,
|
2018-03-16 12:29:42 -07:00
|
|
|
featuredStatusIds: ImmutablePropTypes.list,
|
2017-05-12 05:44:10 -07:00
|
|
|
onScrollToBottom: PropTypes.func,
|
|
|
|
onScrollToTop: PropTypes.func,
|
|
|
|
onScroll: PropTypes.func,
|
2017-06-05 06:20:46 -07:00
|
|
|
trackScroll: PropTypes.bool,
|
2017-05-12 05:44:10 -07:00
|
|
|
shouldUpdateScroll: PropTypes.func,
|
|
|
|
isLoading: PropTypes.bool,
|
2018-01-18 08:25:37 -08:00
|
|
|
isPartial: PropTypes.bool,
|
2017-05-12 05:44:10 -07:00
|
|
|
hasMore: PropTypes.bool,
|
|
|
|
prepend: PropTypes.node,
|
2017-05-20 08:31:47 -07:00
|
|
|
emptyMessage: PropTypes.node,
|
2017-05-12 05:44:10 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static defaultProps = {
|
2017-05-20 08:31:47 -07:00
|
|
|
trackScroll: true,
|
2017-05-12 05:44:10 -07:00
|
|
|
};
|
|
|
|
|
2017-10-05 16:07:59 -07:00
|
|
|
handleMoveUp = id => {
|
|
|
|
const elementIndex = this.props.statusIds.indexOf(id) - 1;
|
|
|
|
this._selectChild(elementIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleMoveDown = id => {
|
|
|
|
const elementIndex = this.props.statusIds.indexOf(id) + 1;
|
|
|
|
this._selectChild(elementIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
_selectChild (index) {
|
|
|
|
const element = this.node.node.querySelector(`article:nth-of-type(${index + 1}) .focusable`);
|
|
|
|
|
|
|
|
if (element) {
|
|
|
|
element.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setRef = c => {
|
|
|
|
this.node = c;
|
|
|
|
}
|
|
|
|
|
2016-08-31 07:15:12 -07:00
|
|
|
render () {
|
2018-03-16 12:29:42 -07:00
|
|
|
const { statusIds, featuredStatusIds, ...other } = this.props;
|
2018-01-18 08:25:37 -08:00
|
|
|
const { isLoading, isPartial } = other;
|
|
|
|
|
|
|
|
if (isPartial) {
|
|
|
|
return (
|
|
|
|
<div className='regeneration-indicator'>
|
|
|
|
<div>
|
|
|
|
<div className='regeneration-indicator__figure' />
|
|
|
|
|
|
|
|
<div className='regeneration-indicator__label'>
|
|
|
|
<FormattedMessage id='regeneration_indicator.label' tagName='strong' defaultMessage='Loading…' />
|
|
|
|
<FormattedMessage id='regeneration_indicator.sublabel' defaultMessage='Your home feed is being prepared!' />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2017-08-28 13:23:44 -07:00
|
|
|
|
2018-03-16 12:29:42 -07:00
|
|
|
let scrollableContent = (isLoading || statusIds.size > 0) ? (
|
|
|
|
statusIds.map(statusId => (
|
2017-10-05 16:07:59 -07:00
|
|
|
<StatusContainer
|
|
|
|
key={statusId}
|
|
|
|
id={statusId}
|
|
|
|
onMoveUp={this.handleMoveUp}
|
|
|
|
onMoveDown={this.handleMoveDown}
|
|
|
|
/>
|
2017-08-28 13:23:44 -07:00
|
|
|
))
|
|
|
|
) : null;
|
|
|
|
|
2018-03-16 12:29:42 -07:00
|
|
|
if (scrollableContent && featuredStatusIds) {
|
|
|
|
scrollableContent = featuredStatusIds.map(statusId => (
|
|
|
|
<StatusContainer
|
|
|
|
key={`f-${statusId}`}
|
|
|
|
id={statusId}
|
|
|
|
featured
|
|
|
|
onMoveUp={this.handleMoveUp}
|
|
|
|
onMoveDown={this.handleMoveDown}
|
|
|
|
/>
|
|
|
|
)).concat(scrollableContent);
|
|
|
|
}
|
|
|
|
|
2017-08-28 13:23:44 -07:00
|
|
|
return (
|
2017-10-05 16:07:59 -07:00
|
|
|
<ScrollableList {...other} ref={this.setRef}>
|
2017-08-28 13:23:44 -07:00
|
|
|
{scrollableContent}
|
|
|
|
</ScrollableList>
|
|
|
|
);
|
2016-08-24 08:56:44 -07:00
|
|
|
}
|
2016-08-31 07:15:12 -07:00
|
|
|
|
2017-04-21 11:05:35 -07:00
|
|
|
}
|