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.
73 lines
1.8 KiB
73 lines
1.8 KiB
8 years ago
|
import React from 'react';
|
||
8 years ago
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||
8 years ago
|
import PropTypes from 'prop-types';
|
||
7 years ago
|
import StatusContainer from 'flavours/glitch/containers/status_container';
|
||
8 years ago
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||
7 years ago
|
import ScrollableList from './scrollable_list';
|
||
8 years ago
|
|
||
8 years ago
|
export default class StatusList extends ImmutablePureComponent {
|
||
8 years ago
|
|
||
8 years ago
|
static propTypes = {
|
||
|
scrollKey: PropTypes.string.isRequired,
|
||
|
statusIds: ImmutablePropTypes.list.isRequired,
|
||
|
onScrollToBottom: PropTypes.func,
|
||
|
onScrollToTop: PropTypes.func,
|
||
|
onScroll: PropTypes.func,
|
||
8 years ago
|
trackScroll: PropTypes.bool,
|
||
8 years ago
|
shouldUpdateScroll: PropTypes.func,
|
||
|
isLoading: PropTypes.bool,
|
||
|
hasMore: PropTypes.bool,
|
||
|
prepend: PropTypes.node,
|
||
8 years ago
|
emptyMessage: PropTypes.node,
|
||
8 years ago
|
};
|
||
|
|
||
|
static defaultProps = {
|
||
8 years ago
|
trackScroll: true,
|
||
8 years ago
|
};
|
||
|
|
||
7 years ago
|
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;
|
||
|
}
|
||
|
|
||
8 years ago
|
render () {
|
||
7 years ago
|
const { statusIds, ...other } = this.props;
|
||
|
const { isLoading } = other;
|
||
|
|
||
|
const scrollableContent = (isLoading || statusIds.size > 0) ? (
|
||
|
statusIds.map((statusId) => (
|
||
7 years ago
|
<StatusContainer
|
||
|
key={statusId}
|
||
|
id={statusId}
|
||
|
onMoveUp={this.handleMoveUp}
|
||
|
onMoveDown={this.handleMoveDown}
|
||
|
/>
|
||
7 years ago
|
))
|
||
|
) : null;
|
||
|
|
||
|
return (
|
||
7 years ago
|
<ScrollableList {...other} ref={this.setRef}>
|
||
7 years ago
|
{scrollableContent}
|
||
|
</ScrollableList>
|
||
|
);
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
8 years ago
|
}
|