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

114 lines
3.8 KiB
JavaScript
Raw Normal View History

import React from 'react'
import PropTypes from 'prop-types'
2020-04-02 04:17:21 +01:00
import { NavLink } from 'react-router-dom'
import { injectIntl, defineMessages, FormattedMessage } from 'react-intl'
import ImmutablePropTypes from 'react-immutable-proptypes'
import ImmutablePureComponent from 'react-immutable-pure-component'
import Icon from './icon'
import Text from './text'
const messages = defineMessages({
filtered: { id: 'status.filtered', defaultMessage: 'Filtered' },
promoted: { id: 'status.promoted', defaultMessage: 'Promoted gab' },
pinned: { id: 'status.pinned', defaultMessage: 'Pinned gab' },
reposted: { id: 'status.reposted_by', defaultMessage: '{name} reposted' },
})
export default
@injectIntl
class StatusPrepend extends ImmutablePureComponent {
static propTypes = {
intl: PropTypes.object.isRequired,
status: ImmutablePropTypes.map,
2020-05-05 06:16:01 +01:00
isComment: PropTypes.bool,
2020-04-22 06:00:11 +01:00
isFeatured: PropTypes.bool,
isPromoted: PropTypes.bool,
2020-04-02 04:17:21 +01:00
}
render() {
const {
intl,
status,
2020-04-22 06:00:11 +01:00
isFeatured,
isPromoted,
2020-05-05 06:16:01 +01:00
isComment,
2020-04-02 04:17:21 +01:00
} = this.props
if (!status) return null
const isRepost = (status.get('reblog', null) !== null && typeof status.get('reblog') === 'object')
2020-05-05 06:16:01 +01:00
if (!isFeatured && !isPromoted && !isRepost && !isComment) return null
let iconId
if (isFeatured) iconId = 'pin'
else if (isPromoted) iconId = 'star'
else if (isRepost) iconId = 'repost'
else if (isComment) iconId = 'comment'
2020-04-02 04:17:21 +01:00
return (
<div className={[_s.default, _s.width100PC, _s.alignItemsStart, _s.borderBottom1PX, _s.borderColorSecondary].join(' ')}>
2020-04-02 04:17:21 +01:00
<div className={[_s.default, _s.width100PC, _s.flexRow, _s.alignItemsCenter, _s.py5, _s.px15].join(' ')}>
<Icon id={iconId} size='12px' className={[_s.colorSecondary, _s.mr5].join(' ')} />
2020-04-02 04:17:21 +01:00
{
2020-05-05 06:16:01 +01:00
isRepost && !isComment &&
2020-04-02 04:17:21 +01:00
<div className={[_s.default, _s.flexRow].join(' ')}>
<Text size='small' color='secondary'>
<FormattedMessage
id='status.reposted_by'
defaultMessage='{name} reposted'
values={{
name: (
<NavLink
className={[_s.noUnderline, _s.underline_onHover].join(' ')}
to={`/${status.getIn(['account', 'acct'])}`}
>
<Text size='small' color='secondary'>
<bdi>
<span dangerouslySetInnerHTML={{ __html: status.getIn(['account', 'display_name_html']) }} />
</bdi>
</Text>
</NavLink>
)
}}
/>
</Text>
</div>
}
{
2020-05-05 06:16:01 +01:00
!isRepost && !isComment &&
2020-04-02 04:17:21 +01:00
<Text color='secondary' size='small'>
2020-04-22 06:00:11 +01:00
{intl.formatMessage(isFeatured ? messages.pinned : messages.promoted)}
2020-04-02 04:17:21 +01:00
</Text>
}
2020-05-05 06:16:01 +01:00
{
isComment &&
<Text color='secondary' size='small'>
<FormattedMessage
id='status.commented_on_this'
defaultMessage='{name} commented on this gab'
values={{
name: (
<NavLink
className={[_s.noUnderline, _s.underline_onHover].join(' ')}
to={`/${status.getIn(['account', 'acct'])}`}
>
<Text size='small' color='secondary'>
<bdi>
<span dangerouslySetInnerHTML={{ __html: status.getIn(['account', 'display_name_html']) }} />
</bdi>
</Text>
</NavLink>
)
}}
/>
</Text>
}
2020-04-02 04:17:21 +01:00
</div>
</div>
)
}
}