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

178 lines
5.3 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-04-02 04:17:21 +01:00
import classNames from 'classnames/bind'
2020-03-25 03:08:43 +00:00
import { openPopover } from '../actions/popover'
import { openModal } from '../actions/modal'
2020-04-22 06:00:11 +01:00
import { me } from '../initial_state'
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-04-02 04:17:21 +01:00
const cx = classNames.bind(_s)
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-04-02 04:17:21 +01:00
reduced: PropTypes.bool,
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
}
2020-03-25 03:08:43 +00:00
setStatusOptionsButton = n => {
this.statusOptionsButton = n
2020-02-21 00:57:29 +00:00
}
render() {
2020-04-02 04:17:21 +01:00
const { status, reduced } = this.props
2020-02-21 00:57:29 +00:00
2020-04-24 04:17:27 +01:00
const statusUrl = `/${status.getIn(['account', 'acct'])}/posts/${status.get('id')}`
2020-02-21 00:57:29 +00:00
2020-04-02 04:17:21 +01:00
const containerClasses = cx({
default: 1,
px15: 1,
py10: !reduced,
pb10: reduced,
})
const avatarSize = reduced ? 20 : 46
2020-04-07 02:53:23 +01:00
const visibilityIcon = 'globe'
2020-04-02 04:17:21 +01:00
2020-02-21 00:57:29 +00:00
return (
2020-04-02 04:17:21 +01:00
<div className={containerClasses}>
2020-03-11 23:56:18 +00:00
<div className={[_s.default, _s.flexRow, _s.mt5].join(' ')}>
2020-02-21 00:57:29 +00:00
2020-04-02 04:17:21 +01:00
{
!reduced &&
<NavLink
to={`/${status.getIn(['account', 'acct'])}`}
title={status.getIn(['account', 'acct'])}
className={[_s.default, _s.mr10].join(' ')}
>
<Avatar account={status.get('account')} size={avatarSize} />
</NavLink>
}
2020-02-21 00:57:29 +00:00
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'])}
>
2020-04-24 04:17:27 +01:00
<DisplayName account={status.get('account')} noRelationship />
2020-02-21 00:57:29 +00:00
</NavLink>
2020-04-02 04:17:21 +01:00
{
2020-04-22 06:00:11 +01:00
!reduced && !!me &&
2020-04-02 04:17:21 +01:00
<Button
2020-04-23 07:13:29 +01:00
isText
2020-04-02 04:17:21 +01:00
backgroundColor='none'
color='none'
icon='ellipsis'
2020-04-23 07:13:29 +01:00
iconSize='20px'
2020-04-29 23:32:49 +01:00
iconClassName={_s.fillSecondary}
2020-04-24 04:17:27 +01:00
className={_s.mlAuto}
2020-04-02 04:17:21 +01:00
onClick={this.handleOpenStatusOptionsPopover}
buttonRef={this.setStatusOptionsButton}
/>
}
2020-02-21 00:57:29 +00:00
</div>
<div className={[_s.default, _s.flexRow, _s.alignItemsCenter, _s.lineHeight15].join(' ')}>
<Button
2020-04-23 07:13:29 +01:00
isText
2020-02-21 00:57:29 +00:00
underlineOnHover
backgroundColor='none'
color='none'
to={statusUrl}
>
<Text size='small' color='secondary'>
<RelativeTimestamp timestamp={status.get('created_at')} />
</Text>
</Button>
<DotTextSeperator />
2020-04-29 23:32:49 +01:00
<Icon id={visibilityIcon} size='12px' className={[_s.default, _s.displayInline, _s.ml5, _s.fillSecondary].join(' ')} />
2020-02-21 00:57:29 +00:00
{
!!status.get('group') &&
<Fragment>
<DotTextSeperator />
<Button
2020-04-23 07:13:29 +01:00
isText
2020-02-21 00:57:29 +00:00
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
2020-04-23 07:13:29 +01:00
isText
2020-02-21 00:57:29 +00:00
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>
)
}
}