2017-05-03 09:04:16 +09:00
|
|
|
import React from 'react';
|
2016-12-04 05:04:57 +09:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2017-04-22 03:05:35 +09:00
|
|
|
import PropTypes from 'prop-types';
|
2017-07-13 18:40:16 +09:00
|
|
|
import StatusContainer from '../../glitch/components/status/container';
|
2017-05-03 09:04:16 +09:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2017-08-29 05:23:44 +09:00
|
|
|
import ScrollableList from './scrollable_list';
|
2016-08-25 00:56:44 +09:00
|
|
|
|
2017-06-24 02:36:54 +09:00
|
|
|
export default class StatusList extends ImmutablePureComponent {
|
2017-04-22 03:05:35 +09:00
|
|
|
|
2017-05-12 21:44:10 +09:00
|
|
|
static propTypes = {
|
|
|
|
scrollKey: PropTypes.string.isRequired,
|
|
|
|
statusIds: ImmutablePropTypes.list.isRequired,
|
|
|
|
onScrollToBottom: PropTypes.func,
|
|
|
|
onScrollToTop: PropTypes.func,
|
|
|
|
onScroll: PropTypes.func,
|
2017-06-05 22:20:46 +09:00
|
|
|
trackScroll: PropTypes.bool,
|
2017-05-12 21:44:10 +09:00
|
|
|
shouldUpdateScroll: PropTypes.func,
|
|
|
|
isLoading: PropTypes.bool,
|
|
|
|
hasMore: PropTypes.bool,
|
|
|
|
prepend: PropTypes.node,
|
2017-05-21 00:31:47 +09:00
|
|
|
emptyMessage: PropTypes.node,
|
2017-05-12 21:44:10 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
static defaultProps = {
|
2017-05-21 00:31:47 +09:00
|
|
|
trackScroll: true,
|
2017-05-12 21:44:10 +09:00
|
|
|
};
|
|
|
|
|
2017-10-06 08:07:59 +09: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 23:15:12 +09:00
|
|
|
render () {
|
2017-08-29 05:23:44 +09:00
|
|
|
const { statusIds, ...other } = this.props;
|
|
|
|
const { isLoading } = other;
|
|
|
|
|
|
|
|
const scrollableContent = (isLoading || statusIds.size > 0) ? (
|
|
|
|
statusIds.map((statusId) => (
|
2017-10-06 08:07:59 +09:00
|
|
|
<StatusContainer
|
|
|
|
key={statusId}
|
|
|
|
id={statusId}
|
|
|
|
onMoveUp={this.handleMoveUp}
|
|
|
|
onMoveDown={this.handleMoveDown}
|
|
|
|
/>
|
2017-08-29 05:23:44 +09:00
|
|
|
))
|
|
|
|
) : null;
|
|
|
|
|
|
|
|
return (
|
2017-10-06 08:07:59 +09:00
|
|
|
<ScrollableList {...other} ref={this.setRef}>
|
2017-08-29 05:23:44 +09:00
|
|
|
{scrollableContent}
|
|
|
|
</ScrollableList>
|
|
|
|
);
|
2016-08-25 00:56:44 +09:00
|
|
|
}
|
2016-08-31 23:15:12 +09:00
|
|
|
|
2017-04-22 03:05:35 +09:00
|
|
|
}
|