gab-social/app/javascript/gabsocial/components/status_header.js

229 lines
6.6 KiB
JavaScript
Raw Normal View History

2020-02-21 00:57:29 +00:00
import { Fragment } from 'react'
import { NavLink } from 'react-router-dom'
import ImmutablePropTypes from 'react-immutable-proptypes'
import ImmutablePureComponent from 'react-immutable-pure-component'
2020-03-25 03:08:43 +00:00
import { openPopover } from '../actions/popover'
import { openModal } from '../actions/modal'
2020-02-21 00:57:29 +00:00
import RelativeTimestamp from './relative_timestamp'
import DisplayName from './display_name'
import Text from './text'
import DotTextSeperator from './dot_text_seperator'
import Icon from './icon'
import Button from './button'
import Avatar from './avatar'
2020-03-26 03:11:32 +00:00
const mapDispatchToProps = (dispatch) => ({
2020-03-27 22:57:03 +00:00
onOpenStatusRevisionsPopover(status) {
dispatch(openModal('STATUS_REVISIONS', {
status,
}))
},
2020-03-26 03:11:32 +00:00
onOpenStatusOptionsPopover(targetRef, status) {
dispatch(openPopover('STATUS_OPTIONS', {
targetRef,
status,
position: 'top',
}))
},
})
2020-03-25 03:08:43 +00:00
export default
2020-03-26 03:11:32 +00:00
@connect(null, mapDispatchToProps)
2020-03-25 03:08:43 +00:00
class StatusHeader extends ImmutablePureComponent {
2020-02-21 00:57:29 +00:00
static propTypes = {
status: ImmutablePropTypes.map,
2020-03-27 22:57:03 +00:00
onOpenStatusRevisionsPopover: PropTypes.func.isRequired,
2020-03-26 03:11:32 +00:00
onOpenStatusOptionsPopover: PropTypes.func.isRequired,
2020-02-21 00:57:29 +00:00
}
2020-03-26 03:11:32 +00:00
handleOpenStatusOptionsPopover = () => {
this.props.onOpenStatusOptionsPopover(this.statusOptionsButton, this.props.status)
2020-02-21 00:57:29 +00:00
}
2020-03-26 03:11:32 +00:00
handleOpenStatusEdits = () => {
2020-03-27 22:57:03 +00:00
this.props.onOpenStatusRevisionsPopover(this.props.status)
2020-02-21 00:57:29 +00:00
}
handleDeleteClick = () => {
this.props.onDelete(this.props.status, this.context.router.history);
}
handleEditClick = () => {
this.props.onEdit(this.props.status);
}
handlePinClick = () => {
this.props.onPin(this.props.status);
}
handleMentionClick = () => {
this.props.onMention(this.props.status.get('account'), this.context.router.history);
}
handleMuteClick = () => {
this.props.onMute(this.props.status.get('account'));
}
handleBlockClick = () => {
this.props.onBlock(this.props.status);
}
handleOpen = () => {
this.context.router.history.push(`/${this.props.status.getIn(['account', 'acct'])}/posts/${this.props.status.get('id')}`);
}
handleEmbed = () => {
this.props.onEmbed(this.props.status);
}
handleReport = () => {
this.props.onReport(this.props.status);
}
handleConversationMuteClick = () => {
this.props.onMuteConversation(this.props.status);
}
handleCopy = () => {
const url = this.props.status.get('url');
const textarea = document.createElement('textarea');
textarea.textContent = url;
textarea.style.position = 'fixed';
document.body.appendChild(textarea);
try {
textarea.select();
document.execCommand('copy');
} catch (e) {
//
} finally {
document.body.removeChild(textarea);
}
}
handleGroupRemoveAccount = () => {
const { status } = this.props;
this.props.onGroupRemoveAccount(status.getIn(['group', 'id']), status.getIn(['account', 'id']));
}
handleGroupRemovePost = () => {
const { status } = this.props;
this.props.onGroupRemoveStatus(status.getIn(['group', 'id']), status.get('id'));
}
2020-03-25 03:08:43 +00:00
setStatusOptionsButton = n => {
this.statusOptionsButton = n
2020-02-21 00:57:29 +00:00
}
render() {
const { status } = this.props
const statusUrl = `/${status.getIn(['account', 'acct'])}/posts/${status.get('id')}`;
return (
2020-03-11 23:56:18 +00:00
<div className={[_s.default, _s.px15, _s.py10].join(' ')}>
<div className={[_s.default, _s.flexRow, _s.mt5].join(' ')}>
2020-02-21 00:57:29 +00:00
<NavLink
to={`/${status.getIn(['account', 'acct'])}`}
title={status.getIn(['account', 'acct'])}
2020-03-11 23:56:18 +00:00
className={[_s.default, _s.mr10].join(' ')}
2020-02-21 00:57:29 +00:00
>
<Avatar account={status.get('account')} size={50} />
</NavLink>
2020-03-11 23:56:18 +00:00
<div className={[_s.default, _s.alignItemsStart, _s.flexGrow1, _s.mt5].join(' ')}>
2020-02-21 00:57:29 +00:00
<div className={[_s.default, _s.flexRow, _s.width100PC, _s.alignItemsStart].join(' ')}>
<NavLink
className={[_s.default, _s.flexRow, _s.alignItemsStart, _s.noUnderline].join(' ')}
to={`/${status.getIn(['account', 'acct'])}`}
title={status.getIn(['account', 'acct'])}
>
<DisplayName account={status.get('account')} />
</NavLink>
<Button
text
backgroundColor='none'
color='none'
icon='ellipsis'
iconWidth='20px'
iconHeight='20px'
2020-03-02 22:26:25 +00:00
iconClassName={_s.fillColorSecondary}
2020-02-21 00:57:29 +00:00
className={_s.marginLeftAuto}
2020-03-26 03:11:32 +00:00
onClick={this.handleOpenStatusOptionsPopover}
2020-03-25 03:08:43 +00:00
buttonRef={this.setStatusOptionsButton}
2020-02-21 00:57:29 +00:00
/>
</div>
<div className={[_s.default, _s.flexRow, _s.alignItemsCenter, _s.lineHeight15].join(' ')}>
<Button
text
underlineOnHover
backgroundColor='none'
color='none'
to={statusUrl}
>
<Text size='small' color='secondary'>
<RelativeTimestamp timestamp={status.get('created_at')} />
</Text>
</Button>
<DotTextSeperator />
2020-03-11 23:56:18 +00:00
<Icon id='globe' width='12px' height='12px' className={[_s.default, _s.displayInline, _s.ml5, _s.fillColorSecondary].join(' ')} />
2020-02-21 00:57:29 +00:00
{
!!status.get('group') &&
<Fragment>
<DotTextSeperator />
<Button
text
underlineOnHover
backgroundColor='none'
color='none'
to={`/groups/${status.getIn(['group', 'id'])}`}
2020-03-11 23:56:18 +00:00
className={_s.ml5}
2020-02-21 00:57:29 +00:00
>
<Text size='small' color='secondary'>
{status.getIn(['group', 'title'])}
</Text>
</Button>
</Fragment>
}
{
status.get('revised_at') !== null &&
<Fragment>
<DotTextSeperator />
<Button
text
underlineOnHover
backgroundColor='none'
color='none'
onClick={this.handleOpenStatusEdits}
2020-03-11 23:56:18 +00:00
className={_s.ml5}
2020-02-21 00:57:29 +00:00
>
<Text size='small' color='secondary'>
Edited
</Text>
</Button>
</Fragment>
}
</div>
</div>
</div>
</div>
)
}
}