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

116 lines
3.1 KiB
JavaScript
Raw Normal View History

2020-03-04 03:45:16 +00:00
import { NavLink } from 'react-router-dom'
import { defineMessages, injectIntl } from 'react-intl'
2020-04-24 04:17:27 +01:00
import ImmutablePropTypes from 'react-immutable-proptypes'
2020-03-04 03:45:16 +00:00
import ImmutablePureComponent from 'react-immutable-pure-component'
2020-03-08 23:02:28 +00:00
import { makeGetStatus } from '../selectors';
2020-03-04 03:45:16 +00:00
import Avatar from './avatar'
import Button from './button'
2020-04-24 04:17:27 +01:00
import CommentHeader from './comment_header'
2020-03-08 23:02:28 +00:00
import StatusContent from './status_content'
2020-04-24 04:17:27 +01:00
import Text from './text'
2020-03-04 03:45:16 +00:00
const messages = defineMessages({
2020-04-24 04:17:27 +01:00
reply: { id: 'status.reply', defaultMessage: 'Reply' },
like: { id: 'status.like', defaultMessage: 'Like' },
2020-03-04 03:45:16 +00:00
})
2020-04-23 07:13:29 +01:00
const makeMapStateToProps = (state, props) => ({
status: makeGetStatus()(state, props)
})
2020-03-08 23:02:28 +00:00
2020-03-04 03:45:16 +00:00
export default
@injectIntl
2020-03-08 23:02:28 +00:00
@connect(makeMapStateToProps)
2020-03-04 03:45:16 +00:00
class Comment extends ImmutablePureComponent {
static propTypes = {
2020-04-24 04:17:27 +01:00
indent: PropTypes.number,
intl: PropTypes.object.isRequired,
2020-03-04 03:45:16 +00:00
status: ImmutablePropTypes.map.isRequired,
2020-03-08 23:02:28 +00:00
}
2020-04-24 04:17:27 +01:00
updateOnProps = [
'status',
'indent',
]
2020-03-04 03:45:16 +00:00
render() {
2020-04-24 04:17:27 +01:00
const {
indent,
intl,
status,
} = this.props
2020-03-04 03:45:16 +00:00
2020-04-08 02:06:59 +01:00
const style = {
paddingLeft: `${indent * 40}px`,
}
// : todo : add media
2020-03-04 03:45:16 +00:00
return (
2020-04-17 06:35:46 +01:00
<div className={[_s.default, _s.px15, _s.mb10, _s.py5].join(' ')} data-comment={status.get('id')}>
2020-04-08 02:06:59 +01:00
<div className={[_s.default].join(' ')} style={style}>
2020-03-08 23:02:28 +00:00
<div className={[_s.default, _s.flexRow].join(' ')}>
<NavLink
to={`/${status.getIn(['account', 'acct'])}`}
title={status.getIn(['account', 'acct'])}
2020-03-11 23:56:18 +00:00
className={[_s.default, _s.mr10, _s.pt5].join(' ')}
2020-03-08 23:02:28 +00:00
>
<Avatar account={status.get('account')} size={32} />
</NavLink>
2020-04-29 03:24:35 +01:00
<div className={[_s.default, _s.flexNormal].join(' ')}>
2020-04-25 18:00:51 +01:00
<div className={[_s.default, _s.px10, _s.pt5, _s.pb10, _s.radiusSmall, _s.backgroundColorSubtle].join(' ')}>
2020-04-24 04:17:27 +01:00
<CommentHeader status={status} />
<StatusContent
status={status}
onClick={this.handleClick}
isComment
collapsable
/>
2020-03-08 23:02:28 +00:00
</div>
2020-04-24 04:17:27 +01:00
<div className={[_s.default, _s.flexRow, _s.mt5].join(' ')}>
<CommentButton title={intl.formatMessage(messages.like)} />
<CommentButton title={intl.formatMessage(messages.reply)} />
<CommentButton title='···' />
2020-03-08 23:02:28 +00:00
</div>
2020-04-24 04:17:27 +01:00
2020-03-08 23:02:28 +00:00
</div>
</div>
2020-03-04 03:45:16 +00:00
2020-03-08 23:02:28 +00:00
</div>
2020-03-04 03:45:16 +00:00
</div>
)
}
}
2020-04-24 04:17:27 +01:00
class CommentButton extends PureComponent {
static propTypes = {
onClick: PropTypes.func.isRequired,
title: PropTypes.string.isRequired,
}
render() {
const { onClick, title } = this.props
return (
<Button
isText
radiusSmall
backgroundColor='none'
color='tertiary'
2020-04-25 18:00:51 +01:00
className={[_s.px5, _s.backgroundColorSubtle_onHover, _s.py2, _s.mr5].join(' ')}
2020-04-24 04:17:27 +01:00
onClick={onClick}
>
<Text size='extraSmall' color='inherit' weight='bold'>
{title}
</Text>
</Button>
)
}
}