2021-10-06 15:50:43 -07:00
|
|
|
import React from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import StatusContainer from 'soapbox/containers/status_container';
|
|
|
|
import { OrderedSet as ImmutableOrderedSet } from 'immutable';
|
2021-10-12 18:03:55 -07:00
|
|
|
import PlaceholderStatus from 'soapbox/features/placeholder/components/placeholder_status';
|
2021-10-06 15:50:43 -07:00
|
|
|
import classNames from 'classnames';
|
|
|
|
|
|
|
|
const mapStateToProps = (state, { id }) => {
|
|
|
|
return {
|
2021-10-12 18:03:55 -07:00
|
|
|
replyToId: state.getIn(['contexts', 'inReplyTos', id]),
|
2021-10-06 15:50:43 -07:00
|
|
|
replyCount: state.getIn(['contexts', 'replies', id], ImmutableOrderedSet()).size,
|
2021-10-12 18:03:55 -07:00
|
|
|
isLoaded: Boolean(state.getIn(['statuses', id])),
|
2021-10-06 15:50:43 -07:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export default @connect(mapStateToProps)
|
|
|
|
class ThreadStatus extends React.Component {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
focusedStatusId: PropTypes.string,
|
|
|
|
replyToId: PropTypes.string,
|
|
|
|
replyCount: PropTypes.number,
|
2021-10-12 18:03:55 -07:00
|
|
|
isLoaded: PropTypes.bool,
|
2021-10-06 15:50:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
renderConnector() {
|
|
|
|
const { focusedStatusId, replyToId, replyCount } = this.props;
|
|
|
|
|
|
|
|
const isConnectedTop = replyToId && replyToId !== focusedStatusId;
|
|
|
|
const isConnectedBottom = replyCount > 0;
|
|
|
|
const isConnected = isConnectedTop || isConnectedBottom;
|
|
|
|
|
|
|
|
if (!isConnected) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={classNames('thread__connector', {
|
|
|
|
'thread__connector--top': isConnectedTop,
|
|
|
|
'thread__connector--bottom': isConnectedBottom,
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2021-10-12 18:03:55 -07:00
|
|
|
const { isLoaded } = this.props;
|
|
|
|
|
2021-10-06 15:50:43 -07:00
|
|
|
return (
|
|
|
|
<div className='thread__status'>
|
|
|
|
{this.renderConnector()}
|
2021-10-12 18:03:55 -07:00
|
|
|
{isLoaded ? (
|
|
|
|
<StatusContainer {...this.props} />
|
|
|
|
) : (
|
|
|
|
<PlaceholderStatus />
|
|
|
|
)}
|
2021-10-06 15:50:43 -07:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|