Disable links on collapsed toots

This commit is contained in:
kibigo! 2017-06-26 15:22:03 -07:00
parent c806fef865
commit 5df7bc3a8b
2 changed files with 14 additions and 3 deletions

View File

@ -272,7 +272,7 @@ class StatusUnextended extends ImmutablePureComponent {
</div> </div>
<StatusContent status={status} onClick={this.handleClick} expanded={isExpanded} onExpandedToggle={this.handleExpandedToggle} onHeightUpdate={this.saveHeight}> <StatusContent status={status} onClick={this.handleClick} expanded={isExpanded} collapsed={isCollapsed} onExpandedToggle={this.handleExpandedToggle} onHeightUpdate={this.saveHeight}>
{isCollapsed ? null : media} {isCollapsed ? null : media}

View File

@ -16,6 +16,7 @@ export default class StatusContent extends React.PureComponent {
static propTypes = { static propTypes = {
status: ImmutablePropTypes.map.isRequired, status: ImmutablePropTypes.map.isRequired,
expanded: PropTypes.bool, expanded: PropTypes.bool,
collapsed: PropTypes.bool,
onExpandedToggle: PropTypes.func, onExpandedToggle: PropTypes.func,
onHeightUpdate: PropTypes.func, onHeightUpdate: PropTypes.func,
onClick: PropTypes.func, onClick: PropTypes.func,
@ -40,6 +41,7 @@ export default class StatusContent extends React.PureComponent {
} else if (link.textContent[0] === '#' || (link.previousSibling && link.previousSibling.textContent && link.previousSibling.textContent[link.previousSibling.textContent.length - 1] === '#')) { } else if (link.textContent[0] === '#' || (link.previousSibling && link.previousSibling.textContent && link.previousSibling.textContent[link.previousSibling.textContent.length - 1] === '#')) {
link.addEventListener('click', this.onHashtagClick.bind(this, link.text), false); link.addEventListener('click', this.onHashtagClick.bind(this, link.text), false);
} else { } else {
link.addEventListener('click', this.onLinkClick.bind(this), false);
link.setAttribute('target', '_blank'); link.setAttribute('target', '_blank');
link.setAttribute('rel', 'noopener'); link.setAttribute('rel', 'noopener');
link.setAttribute('title', link.href); link.setAttribute('title', link.href);
@ -53,10 +55,18 @@ export default class StatusContent extends React.PureComponent {
} }
} }
onLinkClick = (e) => {
if (e.button === 0 && this.props.collapsed) {
e.preventDefault();
if (this.props.onClick) this.props.onClick();
}
}
onMentionClick = (mention, e) => { onMentionClick = (mention, e) => {
if (e.button === 0) { if (e.button === 0) {
e.preventDefault(); e.preventDefault();
this.context.router.history.push(`/accounts/${mention.get('id')}`); if (!this.props.collapsed) this.context.router.history.push(`/accounts/${mention.get('id')}`);
else if (this.props.onClick) this.props.onClick();
} }
} }
@ -65,7 +75,8 @@ export default class StatusContent extends React.PureComponent {
if (e.button === 0) { if (e.button === 0) {
e.preventDefault(); e.preventDefault();
this.context.router.history.push(`/timelines/tag/${hashtag}`); if (!this.props.collapsed) this.context.router.history.push(`/timelines/tag/${hashtag}`);
else if (this.props.onClick) this.props.onClick();
} }
} }