2017-04-21 18:05:35 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-23 15:15:17 +00:00
|
|
|
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2017-05-03 00:04:16 +00:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2023-05-23 15:15:17 +00:00
|
|
|
|
|
|
|
import { debounce } from 'lodash';
|
|
|
|
|
2024-02-01 13:37:04 +00:00
|
|
|
import { TIMELINE_GAP, TIMELINE_SUGGESTIONS } from 'mastodon/actions/timelines';
|
2023-05-23 15:15:17 +00:00
|
|
|
import RegenerationIndicator from 'mastodon/components/regeneration_indicator';
|
2024-02-01 13:37:04 +00:00
|
|
|
import { InlineFollowSuggestions } from 'mastodon/features/home_timeline/components/inline_follow_suggestions';
|
2023-05-23 15:15:17 +00:00
|
|
|
|
|
|
|
import StatusContainer from '../containers/status_container';
|
|
|
|
|
2023-05-24 07:20:39 +00:00
|
|
|
import { LoadGap } from './load_gap';
|
2017-08-28 20:23:44 +00:00
|
|
|
import ScrollableList from './scrollable_list';
|
2016-08-24 15:56:44 +00:00
|
|
|
|
2017-06-23 17:36:54 +00:00
|
|
|
export default class StatusList extends ImmutablePureComponent {
|
2017-04-21 18:05:35 +00:00
|
|
|
|
2017-05-12 12:44:10 +00:00
|
|
|
static propTypes = {
|
|
|
|
scrollKey: PropTypes.string.isRequired,
|
|
|
|
statusIds: ImmutablePropTypes.list.isRequired,
|
2018-03-04 08:19:11 +00:00
|
|
|
featuredStatusIds: ImmutablePropTypes.list,
|
2018-03-05 18:31:40 +00:00
|
|
|
onLoadMore: PropTypes.func,
|
2017-05-12 12:44:10 +00:00
|
|
|
onScrollToTop: PropTypes.func,
|
|
|
|
onScroll: PropTypes.func,
|
2017-06-05 13:20:46 +00:00
|
|
|
trackScroll: PropTypes.bool,
|
2017-05-12 12:44:10 +00:00
|
|
|
isLoading: PropTypes.bool,
|
2018-01-17 22:56:03 +00:00
|
|
|
isPartial: PropTypes.bool,
|
2017-05-12 12:44:10 +00:00
|
|
|
hasMore: PropTypes.bool,
|
|
|
|
prepend: PropTypes.node,
|
2017-05-20 15:31:47 +00:00
|
|
|
emptyMessage: PropTypes.node,
|
2018-05-29 00:01:04 +00:00
|
|
|
alwaysPrepend: PropTypes.bool,
|
2022-02-24 23:34:33 +00:00
|
|
|
withCounters: PropTypes.bool,
|
2018-11-08 20:35:06 +00:00
|
|
|
timelineId: PropTypes.string,
|
2023-05-16 13:36:25 +00:00
|
|
|
lastId: PropTypes.string,
|
2024-07-01 14:45:48 +00:00
|
|
|
bindToDocument: PropTypes.bool,
|
2017-05-12 12:44:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static defaultProps = {
|
2017-05-20 15:31:47 +00:00
|
|
|
trackScroll: true,
|
2017-05-12 12:44:10 +00:00
|
|
|
};
|
|
|
|
|
2018-04-20 16:14:21 +00:00
|
|
|
getFeaturedStatusCount = () => {
|
|
|
|
return this.props.featuredStatusIds ? this.props.featuredStatusIds.size : 0;
|
2023-01-30 00:45:35 +00:00
|
|
|
};
|
2018-04-20 16:14:21 +00:00
|
|
|
|
|
|
|
getCurrentStatusIndex = (id, featured) => {
|
|
|
|
if (featured) {
|
|
|
|
return this.props.featuredStatusIds.indexOf(id);
|
|
|
|
} else {
|
|
|
|
return this.props.statusIds.indexOf(id) + this.getFeaturedStatusCount();
|
|
|
|
}
|
2023-01-30 00:45:35 +00:00
|
|
|
};
|
2018-04-20 16:14:21 +00:00
|
|
|
|
|
|
|
handleMoveUp = (id, featured) => {
|
|
|
|
const elementIndex = this.getCurrentStatusIndex(id, featured) - 1;
|
2019-05-03 04:20:36 +00:00
|
|
|
this._selectChild(elementIndex, true);
|
2023-01-30 00:45:35 +00:00
|
|
|
};
|
2017-10-05 23:07:59 +00:00
|
|
|
|
2018-04-20 16:14:21 +00:00
|
|
|
handleMoveDown = (id, featured) => {
|
|
|
|
const elementIndex = this.getCurrentStatusIndex(id, featured) + 1;
|
2019-05-03 04:20:36 +00:00
|
|
|
this._selectChild(elementIndex, false);
|
2023-01-30 00:45:35 +00:00
|
|
|
};
|
2017-10-05 23:07:59 +00:00
|
|
|
|
2018-03-24 14:25:15 +00:00
|
|
|
handleLoadOlder = debounce(() => {
|
2023-05-16 13:36:25 +00:00
|
|
|
const { statusIds, lastId, onLoadMore } = this.props;
|
|
|
|
onLoadMore(lastId || (statusIds.size > 0 ? statusIds.last() : undefined));
|
2023-01-30 00:45:35 +00:00
|
|
|
}, 300, { leading: true });
|
2018-03-24 14:25:15 +00:00
|
|
|
|
2019-05-03 04:20:36 +00:00
|
|
|
_selectChild (index, align_top) {
|
|
|
|
const container = this.node.node;
|
|
|
|
const element = container.querySelector(`article:nth-of-type(${index + 1}) .focusable`);
|
2017-10-05 23:07:59 +00:00
|
|
|
|
|
|
|
if (element) {
|
2019-05-03 04:20:36 +00:00
|
|
|
if (align_top && container.scrollTop > element.offsetTop) {
|
|
|
|
element.scrollIntoView(true);
|
|
|
|
} else if (!align_top && container.scrollTop + container.clientHeight < element.offsetTop + element.offsetHeight) {
|
|
|
|
element.scrollIntoView(false);
|
|
|
|
}
|
2017-10-05 23:07:59 +00:00
|
|
|
element.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setRef = c => {
|
|
|
|
this.node = c;
|
2023-01-30 00:45:35 +00:00
|
|
|
};
|
2017-10-05 23:07:59 +00:00
|
|
|
|
2016-08-31 14:15:12 +00:00
|
|
|
render () {
|
2021-07-13 13:45:17 +00:00
|
|
|
const { statusIds, featuredStatusIds, onLoadMore, timelineId, ...other } = this.props;
|
2018-01-17 22:56:03 +00:00
|
|
|
const { isLoading, isPartial } = other;
|
|
|
|
|
|
|
|
if (isPartial) {
|
2019-10-06 20:11:17 +00:00
|
|
|
return <RegenerationIndicator />;
|
2018-01-17 22:56:03 +00:00
|
|
|
}
|
2017-08-28 20:23:44 +00:00
|
|
|
|
2018-03-04 08:19:11 +00:00
|
|
|
let scrollableContent = (isLoading || statusIds.size > 0) ? (
|
2024-02-01 13:37:04 +00:00
|
|
|
statusIds.map((statusId, index) => {
|
|
|
|
switch(statusId) {
|
|
|
|
case TIMELINE_SUGGESTIONS:
|
|
|
|
return (
|
|
|
|
<InlineFollowSuggestions
|
|
|
|
key='inline-follow-suggestions'
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
case TIMELINE_GAP:
|
|
|
|
return (
|
|
|
|
<LoadGap
|
|
|
|
key={'gap:' + statusIds.get(index + 1)}
|
|
|
|
disabled={isLoading}
|
2024-07-18 14:36:09 +00:00
|
|
|
param={index > 0 ? statusIds.get(index - 1) : null}
|
2024-02-01 13:37:04 +00:00
|
|
|
onClick={onLoadMore}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
default:
|
|
|
|
return (
|
|
|
|
<StatusContainer
|
|
|
|
key={statusId}
|
|
|
|
id={statusId}
|
|
|
|
onMoveUp={this.handleMoveUp}
|
|
|
|
onMoveDown={this.handleMoveDown}
|
|
|
|
contextType={timelineId}
|
|
|
|
scrollKey={this.props.scrollKey}
|
|
|
|
showThread
|
|
|
|
withCounters={this.props.withCounters}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
})
|
2017-08-28 20:23:44 +00:00
|
|
|
) : null;
|
|
|
|
|
2018-03-04 08:19:11 +00:00
|
|
|
if (scrollableContent && featuredStatusIds) {
|
|
|
|
scrollableContent = featuredStatusIds.map(statusId => (
|
|
|
|
<StatusContainer
|
|
|
|
key={`f-${statusId}`}
|
|
|
|
id={statusId}
|
|
|
|
featured
|
|
|
|
onMoveUp={this.handleMoveUp}
|
|
|
|
onMoveDown={this.handleMoveDown}
|
2018-06-29 13:34:36 +00:00
|
|
|
contextType={timelineId}
|
2018-11-08 20:08:57 +00:00
|
|
|
showThread
|
2022-02-24 23:34:33 +00:00
|
|
|
withCounters={this.props.withCounters}
|
2018-03-04 08:19:11 +00:00
|
|
|
/>
|
|
|
|
)).concat(scrollableContent);
|
|
|
|
}
|
|
|
|
|
2017-08-28 20:23:44 +00:00
|
|
|
return (
|
2021-07-13 13:45:17 +00:00
|
|
|
<ScrollableList {...other} showLoading={isLoading && statusIds.size === 0} onLoadMore={onLoadMore && this.handleLoadOlder} ref={this.setRef}>
|
2017-08-28 20:23:44 +00:00
|
|
|
{scrollableContent}
|
|
|
|
</ScrollableList>
|
|
|
|
);
|
2016-08-24 15:56:44 +00:00
|
|
|
}
|
2016-08-31 14:15:12 +00:00
|
|
|
|
2017-04-21 18:05:35 +00:00
|
|
|
}
|