2020-02-28 15:20:47 +00:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes'
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component'
|
|
|
|
import { defineMessages, injectIntl } from 'react-intl'
|
2020-02-08 06:12:01 +00:00
|
|
|
import classNames from 'classnames/bind'
|
2020-03-07 04:53:28 +00:00
|
|
|
import Text from './text'
|
2020-03-06 15:38:22 +00:00
|
|
|
import StatusActionBarItem from './status_action_bar_item'
|
2019-08-07 06:02:36 +01:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
2020-02-08 22:57:09 +00:00
|
|
|
comment: { id: 'status.comment', defaultMessage: 'Comment' },
|
|
|
|
share: { id: 'status.share', defaultMessage: 'Share' },
|
2020-04-22 06:00:11 +01:00
|
|
|
repost: { id: 'status.repost', defaultMessage: 'Repost' },
|
2020-03-04 22:50:15 +00:00
|
|
|
cannot_repost: { id: 'status.cannot_repost', defaultMessage: 'This post cannot be reposted' },
|
2020-02-08 22:57:09 +00:00
|
|
|
like: { id: 'status.like', defaultMessage: 'Like' },
|
2020-04-02 17:57:04 +01:00
|
|
|
likesLabel: { id: 'likes.label', defaultMessage: '{number, plural, one {# like} other {# likes}}' },
|
|
|
|
repostsLabel: { id: 'reposts.label', defaultMessage: '{number, plural, one {# repost} other {# reposts}}' },
|
|
|
|
commentsLabel: { id: 'comments.label', defaultMessage: '{number, plural, one {# comment} other {# comments}}' },
|
2020-02-28 15:20:47 +00:00
|
|
|
})
|
2019-08-07 06:02:36 +01:00
|
|
|
|
2020-02-19 23:57:07 +00:00
|
|
|
const cx = classNames.bind(_s)
|
|
|
|
|
2020-02-25 16:04:44 +00:00
|
|
|
export default
|
2019-08-07 06:02:36 +01:00
|
|
|
@injectIntl
|
|
|
|
class StatusActionBar extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
router: PropTypes.object,
|
2020-02-28 15:20:47 +00:00
|
|
|
}
|
2019-08-07 06:02:36 +01:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
intl: PropTypes.object.isRequired,
|
2020-04-22 06:00:11 +01:00
|
|
|
onFavorite: PropTypes.func.isRequired,
|
|
|
|
onShare: PropTypes.func.isRequired,
|
|
|
|
onReply: PropTypes.func.isRequired,
|
|
|
|
onQuote: PropTypes.func.isRequired,
|
|
|
|
status: ImmutablePropTypes.map.isRequired,
|
2020-02-28 15:20:47 +00:00
|
|
|
}
|
2019-08-07 06:02:36 +01:00
|
|
|
|
2020-04-22 06:00:11 +01:00
|
|
|
updateOnProps = ['status']
|
2019-08-07 06:02:36 +01:00
|
|
|
|
|
|
|
handleReplyClick = () => {
|
2020-04-22 06:00:11 +01:00
|
|
|
this.props.onReply(this.props.status, this.context.router.history)
|
2019-08-07 06:02:36 +01:00
|
|
|
}
|
|
|
|
|
2020-03-04 22:26:01 +00:00
|
|
|
handleFavoriteClick = () => {
|
2020-04-22 06:00:11 +01:00
|
|
|
this.props.onFavorite(this.props.status)
|
2019-08-07 06:02:36 +01:00
|
|
|
}
|
|
|
|
|
2020-04-22 06:00:11 +01:00
|
|
|
handleRepostClick = (e) => {
|
|
|
|
// this.props.onRepost(this.props.status, e)
|
|
|
|
this.props.onQuote(this.props.status, this.context.router.history)
|
2019-08-07 06:02:36 +01:00
|
|
|
}
|
|
|
|
|
2020-03-07 04:53:28 +00:00
|
|
|
handleShareClick = () => {
|
2020-04-22 06:00:11 +01:00
|
|
|
this.props.onShare(this.shareButton, this.props.status)
|
2020-03-25 03:08:43 +00:00
|
|
|
}
|
|
|
|
|
2020-04-17 06:35:46 +01:00
|
|
|
openLikesList = () => {
|
2020-04-22 06:00:11 +01:00
|
|
|
// : todo :
|
2020-04-17 06:35:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
toggleCommentsVisible = () => {
|
2020-04-22 06:00:11 +01:00
|
|
|
// : todo :
|
2020-04-17 06:35:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
openRepostsList = () => {
|
2020-04-22 06:00:11 +01:00
|
|
|
// : todo :
|
2020-04-17 06:35:46 +01:00
|
|
|
}
|
|
|
|
|
2020-03-25 03:08:43 +00:00
|
|
|
setShareButton = (n) => {
|
|
|
|
this.shareButton = n
|
2020-03-07 04:53:28 +00:00
|
|
|
}
|
|
|
|
|
2020-02-28 15:20:47 +00:00
|
|
|
render() {
|
2020-04-22 06:00:11 +01:00
|
|
|
const { status, intl } = this.props
|
2019-08-07 06:02:36 +01:00
|
|
|
|
2020-02-28 15:20:47 +00:00
|
|
|
const publicStatus = ['public', 'unlisted'].includes(status.get('visibility'))
|
2019-08-07 06:02:36 +01:00
|
|
|
|
2020-02-28 15:20:47 +00:00
|
|
|
const replyCount = status.get('replies_count')
|
2020-03-04 22:50:15 +00:00
|
|
|
const repostCount = status.get('reblogs_count')
|
2020-04-07 02:53:23 +01:00
|
|
|
const favoriteCount = status.get('favourites_count')
|
2019-08-07 06:02:36 +01:00
|
|
|
|
2020-03-04 22:50:15 +00:00
|
|
|
const hasInteractions = favoriteCount > 0 || replyCount > 0 || repostCount > 0
|
2020-04-02 04:17:21 +01:00
|
|
|
const shouldCondense = (
|
|
|
|
!!status.get('card') ||
|
|
|
|
status.get('media_attachments').size > 0 ||
|
|
|
|
!!status.get('quote')
|
|
|
|
) && !hasInteractions
|
2020-02-14 00:40:04 +00:00
|
|
|
|
|
|
|
const containerClasses = cx({
|
|
|
|
default: 1,
|
2020-03-11 23:56:18 +00:00
|
|
|
px10: 1,
|
|
|
|
mt10: !shouldCondense,
|
|
|
|
mt5: shouldCondense,
|
2020-02-14 00:40:04 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
const innerContainerClasses = cx({
|
|
|
|
default: 1,
|
2020-03-11 23:56:18 +00:00
|
|
|
py2: 1,
|
2020-02-14 00:40:04 +00:00
|
|
|
flexRow: 1,
|
|
|
|
width100PC: 1,
|
|
|
|
borderTop1PX: !shouldCondense,
|
2020-02-21 00:57:29 +00:00
|
|
|
borderColorSecondary: !shouldCondense,
|
2020-03-11 23:56:18 +00:00
|
|
|
mt5: hasInteractions,
|
2020-02-14 00:40:04 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
const interactionBtnClasses = cx({
|
|
|
|
default: 1,
|
|
|
|
text: 1,
|
|
|
|
cursorPointer: 1,
|
|
|
|
fontWeightNormal: 1,
|
2020-04-17 06:35:46 +01:00
|
|
|
underline_onHover: 1,
|
2020-03-11 23:56:18 +00:00
|
|
|
mr10: 1,
|
|
|
|
py5: 1,
|
2020-02-14 00:40:04 +00:00
|
|
|
})
|
|
|
|
|
2020-02-08 06:12:01 +00:00
|
|
|
return (
|
2020-02-14 00:40:04 +00:00
|
|
|
<div className={containerClasses}>
|
|
|
|
{
|
|
|
|
hasInteractions &&
|
2020-03-11 23:56:18 +00:00
|
|
|
<div className={[_s.default, _s.flexRow, _s.px5].join(' ')}>
|
2020-03-07 04:53:28 +00:00
|
|
|
{
|
|
|
|
favoriteCount > 0 &&
|
2020-04-17 06:35:46 +01:00
|
|
|
<button className={interactionBtnClasses} onClick={this.openLikesList}>
|
2020-03-26 03:11:32 +00:00
|
|
|
<Text color='secondary' size='small'>
|
2020-04-22 06:00:11 +01:00
|
|
|
{intl.formatMessage(messages.likesLabel, {
|
2020-04-02 17:57:04 +01:00
|
|
|
number: favoriteCount,
|
|
|
|
})}
|
2020-03-07 04:53:28 +00:00
|
|
|
</Text>
|
2020-02-14 00:40:04 +00:00
|
|
|
</button>
|
|
|
|
}
|
2020-03-07 04:53:28 +00:00
|
|
|
{
|
|
|
|
replyCount > 0 &&
|
2020-04-17 06:35:46 +01:00
|
|
|
<button className={interactionBtnClasses} onClick={this.toggleCommentsVisible}>
|
2020-03-26 03:11:32 +00:00
|
|
|
<Text color='secondary' size='small'>
|
2020-04-22 06:00:11 +01:00
|
|
|
{intl.formatMessage(messages.commentsLabel, {
|
2020-04-02 17:57:04 +01:00
|
|
|
number: replyCount,
|
|
|
|
})}
|
2020-03-07 04:53:28 +00:00
|
|
|
</Text>
|
2020-02-14 00:40:04 +00:00
|
|
|
</button>
|
|
|
|
}
|
2020-03-07 04:53:28 +00:00
|
|
|
{
|
|
|
|
repostCount > 0 &&
|
2020-04-17 06:35:46 +01:00
|
|
|
<button className={interactionBtnClasses} onClick={this.openRepostsList}>
|
2020-03-26 03:11:32 +00:00
|
|
|
<Text color='secondary' size='small'>
|
2020-04-22 06:00:11 +01:00
|
|
|
{intl.formatMessage(messages.repostsLabel, {
|
2020-04-02 17:57:04 +01:00
|
|
|
number: repostCount,
|
|
|
|
})}
|
2020-03-07 04:53:28 +00:00
|
|
|
</Text>
|
2020-02-14 00:40:04 +00:00
|
|
|
</button>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
<div className={innerContainerClasses}>
|
2020-03-11 23:56:18 +00:00
|
|
|
<div className={[_s.default, _s.flexRow, _s.py2, _s.width100PC].join(' ')}>
|
2020-03-07 04:53:28 +00:00
|
|
|
<StatusActionBarItem
|
2020-04-22 06:00:11 +01:00
|
|
|
title={intl.formatMessage(messages.like)}
|
2020-04-02 17:57:04 +01:00
|
|
|
icon={!!status.get('favourited') ? 'liked' : 'like'}
|
|
|
|
active={!!status.get('favourited')}
|
2020-03-07 04:53:28 +00:00
|
|
|
onClick={this.handleFavoriteClick}
|
|
|
|
/>
|
|
|
|
<StatusActionBarItem
|
2020-04-22 06:00:11 +01:00
|
|
|
title={intl.formatMessage(messages.comment)}
|
2020-03-07 04:53:28 +00:00
|
|
|
icon='comment'
|
|
|
|
onClick={this.handleReplyClick}
|
|
|
|
/>
|
|
|
|
<StatusActionBarItem
|
2020-04-22 06:00:11 +01:00
|
|
|
title={intl.formatMessage(messages.repost)}
|
|
|
|
altTitle={!publicStatus ? intl.formatMessage(messages.cannot_repost) : ''}
|
2020-04-07 02:53:23 +01:00
|
|
|
icon={!publicStatus ? 'lock' : 'repost'}
|
2020-03-07 04:53:28 +00:00
|
|
|
disabled={!publicStatus}
|
|
|
|
active={!!status.get('reblogged')}
|
|
|
|
onClick={this.handleRepostClick}
|
|
|
|
/>
|
|
|
|
<StatusActionBarItem
|
2020-03-25 03:08:43 +00:00
|
|
|
buttonRef={this.setShareButton}
|
2020-04-22 06:00:11 +01:00
|
|
|
title={intl.formatMessage(messages.share)}
|
2020-03-07 04:53:28 +00:00
|
|
|
icon='share'
|
|
|
|
onClick={this.handleShareClick}
|
|
|
|
/>
|
2020-02-14 00:40:04 +00:00
|
|
|
</div>
|
2019-08-07 06:02:36 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-02-28 15:20:47 +00:00
|
|
|
)
|
2019-08-07 06:02:36 +01:00
|
|
|
}
|
|
|
|
|
2020-04-22 06:00:11 +01:00
|
|
|
}
|