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-04-24 04:17:27 +01:00
|
|
|
import { NavLink } from 'react-router-dom'
|
2020-05-01 06:50:27 +01:00
|
|
|
import { compactMode } from '../initial_state'
|
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'
|
2020-04-29 23:32:49 +01:00
|
|
|
import {
|
|
|
|
CX,
|
|
|
|
BREAKPOINT_EXTRA_SMALL,
|
|
|
|
} from '../constants'
|
|
|
|
import Responsive from '../features/ui/util/responsive_component'
|
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-05-01 06:50:27 +01:00
|
|
|
const NOU = (num) => {
|
|
|
|
return num <= 0 ? undefined : num
|
|
|
|
}
|
|
|
|
|
2020-02-25 16:04:44 +00:00
|
|
|
export default
|
2019-08-07 06:02:36 +01:00
|
|
|
@injectIntl
|
|
|
|
class StatusActionBar extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
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,
|
2020-04-24 04:17:27 +01:00
|
|
|
onRepost: PropTypes.func.isRequired,
|
2020-04-22 06:00:11 +01:00
|
|
|
status: ImmutablePropTypes.map.isRequired,
|
2020-05-03 06:22:49 +01:00
|
|
|
onOpenLikes: PropTypes.func.isRequired,
|
|
|
|
onOpenReposts: PropTypes.func.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-05-02 07:25:55 +01:00
|
|
|
this.props.onReply(this.props.status, null, true)
|
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) => {
|
2020-04-24 04:17:27 +01:00
|
|
|
this.props.onRepost(this.repostButton, this.props.status, e)
|
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-05-03 06:22:49 +01:00
|
|
|
this.props.onOpenLikes(this.props.status)
|
2020-04-17 06:35:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
openRepostsList = () => {
|
2020-05-03 06:22:49 +01:00
|
|
|
this.props.onOpenReposts(this.props.status)
|
2020-04-17 06:35:46 +01:00
|
|
|
}
|
|
|
|
|
2020-04-24 04:17:27 +01:00
|
|
|
setRepostButton = (n) => {
|
|
|
|
this.repostButton = n
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2020-04-24 04:17:27 +01:00
|
|
|
const statusUrl = `/${status.getIn(['account', 'acct'])}/posts/${status.get('id')}`
|
|
|
|
|
2020-04-29 23:32:49 +01:00
|
|
|
const containerClasses = CX({
|
2020-02-14 00:40:04 +00:00
|
|
|
default: 1,
|
2020-03-11 23:56:18 +00:00
|
|
|
px10: 1,
|
|
|
|
mt10: !shouldCondense,
|
|
|
|
mt5: shouldCondense,
|
2020-02-14 00:40:04 +00:00
|
|
|
})
|
|
|
|
|
2020-04-29 23:32:49 +01:00
|
|
|
const innerContainerClasses = CX({
|
2020-02-14 00:40:04 +00:00
|
|
|
default: 1,
|
2020-03-11 23:56:18 +00:00
|
|
|
py2: 1,
|
2020-02-14 00:40:04 +00:00
|
|
|
flexRow: 1,
|
|
|
|
width100PC: 1,
|
2020-05-01 06:50:27 +01:00
|
|
|
borderTop1PX: !shouldCondense && !compactMode,
|
|
|
|
borderColorSecondary: !shouldCondense && !compactMode,
|
|
|
|
mt5: hasInteractions && !compactMode,
|
2020-02-14 00:40:04 +00:00
|
|
|
})
|
|
|
|
|
2020-04-29 23:32:49 +01:00
|
|
|
const interactionBtnClasses = CX({
|
2020-02-14 00:40:04 +00:00
|
|
|
default: 1,
|
|
|
|
text: 1,
|
|
|
|
cursorPointer: 1,
|
|
|
|
fontWeightNormal: 1,
|
2020-04-24 04:17:27 +01:00
|
|
|
noUnderline: 1,
|
2020-04-17 06:35:46 +01:00
|
|
|
underline_onHover: 1,
|
2020-04-29 23:32:49 +01:00
|
|
|
bgTransparent: 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}>
|
|
|
|
{
|
2020-05-01 06:50:27 +01:00
|
|
|
hasInteractions && !compactMode &&
|
2020-04-24 04:17:27 +01:00
|
|
|
<div className={[_s.default, _s.flexRow, _s.alignItemsEnd, _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-24 04:17:27 +01:00
|
|
|
<NavLink
|
|
|
|
className={interactionBtnClasses}
|
|
|
|
to={statusUrl}
|
|
|
|
>
|
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-04-24 04:17:27 +01:00
|
|
|
</NavLink>
|
2020-02-14 00:40:04 +00:00
|
|
|
}
|
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-05-01 06:50:27 +01:00
|
|
|
title={compactMode ? NOU(favoriteCount) : 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-05-01 06:50:27 +01:00
|
|
|
title={compactMode ? NOU(replyCount) : intl.formatMessage(messages.comment)}
|
2020-03-07 04:53:28 +00:00
|
|
|
icon='comment'
|
|
|
|
onClick={this.handleReplyClick}
|
|
|
|
/>
|
|
|
|
<StatusActionBarItem
|
2020-05-01 06:50:27 +01:00
|
|
|
title={compactMode ? NOU(repostCount) : intl.formatMessage(messages.repost)}
|
2020-04-22 06:00:11 +01:00
|
|
|
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')}
|
2020-04-24 04:17:27 +01:00
|
|
|
buttonRef={this.setRepostButton}
|
2020-03-07 04:53:28 +00:00
|
|
|
onClick={this.handleRepostClick}
|
|
|
|
/>
|
2020-04-29 23:32:49 +01:00
|
|
|
<Responsive min={BREAKPOINT_EXTRA_SMALL}>
|
|
|
|
<StatusActionBarItem
|
|
|
|
buttonRef={this.setShareButton}
|
2020-05-01 06:50:27 +01:00
|
|
|
title={compactMode ? '' : intl.formatMessage(messages.share)}
|
2020-04-29 23:32:49 +01:00
|
|
|
icon='share'
|
|
|
|
onClick={this.handleShareClick}
|
|
|
|
/>
|
|
|
|
</Responsive>
|
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
|
|
|
}
|