2020-08-17 21:07:16 +01:00
|
|
|
import React from 'react'
|
2020-08-17 21:59:29 +01:00
|
|
|
import PropTypes from 'prop-types'
|
2020-08-17 21:39:25 +01:00
|
|
|
import { connect } from 'react-redux'
|
2020-03-02 22:26:25 +00:00
|
|
|
import { NavLink } from 'react-router-dom'
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes'
|
|
|
|
import { defineMessages, injectIntl } from 'react-intl'
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component'
|
|
|
|
import { me } from '../initial_state'
|
2020-09-14 17:47:46 +01:00
|
|
|
import { CX } from '../constants'
|
2020-04-11 23:29:19 +01:00
|
|
|
import {
|
|
|
|
followAccount,
|
|
|
|
unfollowAccount,
|
|
|
|
blockAccount,
|
|
|
|
unblockAccount,
|
|
|
|
muteAccount,
|
|
|
|
unmuteAccount,
|
|
|
|
} from '../actions/accounts'
|
|
|
|
import { openModal } from '../actions/modal'
|
|
|
|
import { initMuteModal } from '../actions/mutes'
|
|
|
|
import { unfollowModal } from '../initial_state'
|
|
|
|
import { makeGetAccount } from '../selectors'
|
2020-04-23 07:13:29 +01:00
|
|
|
import AccountActionButton from './account_action_button'
|
2020-03-02 22:26:25 +00:00
|
|
|
import Avatar from './avatar'
|
|
|
|
import DisplayName from './display_name'
|
|
|
|
import Button from './button'
|
2020-08-07 05:05:22 +01:00
|
|
|
import Text from './text'
|
2020-12-03 04:22:51 +00:00
|
|
|
|
2020-03-02 22:26:25 +00:00
|
|
|
class Account extends ImmutablePureComponent {
|
|
|
|
|
2020-06-11 04:27:03 +01:00
|
|
|
handleAction = (e) => {
|
|
|
|
this.props.onActionClick(this.props.account, e)
|
2020-12-03 04:22:51 +00:00
|
|
|
e.preventDefault()
|
|
|
|
return false
|
2020-03-02 22:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleUnrequest = () => {
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
account,
|
|
|
|
intl,
|
2020-04-22 06:00:11 +01:00
|
|
|
isHidden,
|
2020-03-02 22:26:25 +00:00
|
|
|
onActionClick,
|
|
|
|
actionIcon,
|
|
|
|
actionTitle,
|
|
|
|
compact,
|
2020-03-14 17:31:29 +00:00
|
|
|
expanded,
|
2020-03-02 22:26:25 +00:00
|
|
|
dismissAction,
|
|
|
|
showDismiss,
|
2020-04-29 23:32:49 +01:00
|
|
|
withBio,
|
2020-09-14 17:47:46 +01:00
|
|
|
isCard,
|
2020-03-02 22:26:25 +00:00
|
|
|
} = this.props
|
|
|
|
|
|
|
|
if (!account) return null
|
|
|
|
|
2020-04-22 06:00:11 +01:00
|
|
|
if (isHidden) {
|
2020-03-02 22:26:25 +00:00
|
|
|
return (
|
2020-08-17 21:07:16 +01:00
|
|
|
<React.Fragment>
|
2020-03-02 22:26:25 +00:00
|
|
|
{account.get('display_name')}
|
2020-04-24 04:17:27 +01:00
|
|
|
{`@${account.get('username')}`}
|
2020-08-17 21:07:16 +01:00
|
|
|
</React.Fragment>
|
2020-03-02 22:26:25 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-12-21 00:28:32 +00:00
|
|
|
const actionButton = (onActionClick && (actionIcon || actionTitle)) ? (
|
2020-04-23 07:13:29 +01:00
|
|
|
<Button
|
|
|
|
onClick={this.handleAction}
|
|
|
|
isOutline={true}
|
|
|
|
color='brand'
|
|
|
|
backgroundColor='none'
|
2020-08-18 21:43:06 +01:00
|
|
|
className={[_s.px10, _s.flexRow, _s.aiCenter].join(' ')}
|
2020-05-03 06:22:49 +01:00
|
|
|
icon={actionIcon}
|
|
|
|
iconSize='10px'
|
2020-04-23 07:13:29 +01:00
|
|
|
>
|
2020-08-07 23:27:07 +01:00
|
|
|
{
|
|
|
|
!!actionTitle &&
|
|
|
|
<Text color='inherit' className={_s.ml5}>
|
|
|
|
{actionTitle}
|
|
|
|
</Text>
|
|
|
|
}
|
2020-03-02 22:26:25 +00:00
|
|
|
</Button>
|
2020-04-23 07:13:29 +01:00
|
|
|
) : <AccountActionButton account={account} isSmall />
|
2020-03-02 22:26:25 +00:00
|
|
|
|
2020-11-25 21:22:37 +00:00
|
|
|
const avatarSize = compact ? 40 : 52
|
2020-04-23 07:13:29 +01:00
|
|
|
const dismissBtn = !showDismiss ? null : (
|
2020-03-02 22:26:25 +00:00
|
|
|
<Button
|
2020-04-23 07:13:29 +01:00
|
|
|
isNarrow
|
2020-03-02 22:26:25 +00:00
|
|
|
backgroundColor='none'
|
2020-08-18 21:43:06 +01:00
|
|
|
className={[_s.aiEnd, _s.px5]}
|
2020-03-02 22:26:25 +00:00
|
|
|
onClick={dismissAction}
|
|
|
|
icon='close'
|
2020-04-23 07:13:29 +01:00
|
|
|
iconSize='8px'
|
2020-08-18 21:43:06 +01:00
|
|
|
iconClassName={_s.cSecondary}
|
2020-03-02 22:26:25 +00:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
|
2020-04-29 23:32:49 +01:00
|
|
|
const content = { __html: account.get('note_emojified') }
|
|
|
|
|
2020-09-14 17:47:46 +01:00
|
|
|
const buttonClasses = CX({
|
|
|
|
d: 1,
|
|
|
|
pt2: 1,
|
|
|
|
pr5: 1,
|
|
|
|
noUnderline: 1,
|
|
|
|
overflowHidden: 1,
|
|
|
|
flexNormal: 1,
|
|
|
|
aiStart: !isCard,
|
|
|
|
aiCenter: isCard,
|
|
|
|
})
|
|
|
|
|
|
|
|
const containerClasses = CX({
|
|
|
|
d: 1,
|
|
|
|
px15: 1,
|
|
|
|
py10: 1,
|
|
|
|
bgSubtle_onHover: 1,
|
|
|
|
borderBottom1PX: !isCard,
|
|
|
|
borderColorSecondary: !isCard,
|
|
|
|
})
|
|
|
|
|
|
|
|
const innerContainerClasses = CX({
|
|
|
|
d: 1,
|
|
|
|
flexRow: !isCard,
|
|
|
|
aiStart: !isCard,
|
|
|
|
aiCenter: isCard,
|
|
|
|
})
|
|
|
|
|
|
|
|
const displayNameWrapperClasses = CX({
|
|
|
|
py10: isCard,
|
|
|
|
})
|
|
|
|
|
2020-03-02 22:26:25 +00:00
|
|
|
return (
|
2020-09-14 17:47:46 +01:00
|
|
|
<div className={containerClasses}>
|
|
|
|
<div className={innerContainerClasses}>
|
2020-03-02 22:26:25 +00:00
|
|
|
|
|
|
|
<NavLink
|
2020-08-18 21:49:11 +01:00
|
|
|
className={[_s.d, _s.noUnderline].join(' ')}
|
2020-03-02 22:26:25 +00:00
|
|
|
title={account.get('acct')}
|
|
|
|
to={`/${account.get('acct')}`}
|
|
|
|
>
|
|
|
|
<Avatar account={account} size={avatarSize} />
|
|
|
|
</NavLink>
|
|
|
|
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.px10, _s.overflowHidden, _s.flexNormal].join(' ')}>
|
|
|
|
<div className={[_s.d, _s.flexRow, _s.aiCenter].join(' ')}>
|
2020-04-29 23:32:49 +01:00
|
|
|
<NavLink
|
|
|
|
title={account.get('acct')}
|
|
|
|
to={`/${account.get('acct')}`}
|
2020-09-14 17:47:46 +01:00
|
|
|
className={buttonClasses}
|
2020-04-29 23:32:49 +01:00
|
|
|
>
|
2020-09-14 17:47:46 +01:00
|
|
|
<div className={displayNameWrapperClasses}>
|
|
|
|
<DisplayName account={account} isMultiline={compact || isCard} />
|
|
|
|
</div>
|
2020-04-29 23:32:49 +01:00
|
|
|
{!compact && actionButton}
|
|
|
|
</NavLink>
|
|
|
|
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d].join(' ')}>
|
2020-04-29 23:32:49 +01:00
|
|
|
{dismissBtn}
|
|
|
|
{compact && actionButton}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{
|
|
|
|
withBio &&
|
|
|
|
<div className={[_s.py5, _s.dangerousContent].join(' ')} dangerouslySetInnerHTML={content} />
|
|
|
|
}
|
2020-03-02 22:26:25 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-08-18 01:57:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
const makeMapStateToProps = (state, props) => ({
|
|
|
|
account: makeGetAccount()(state, props.id),
|
|
|
|
})
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
|
|
|
|
|
|
onFollow (account) {
|
|
|
|
if (account.getIn(['relationship', 'following']) || account.getIn(['relationship', 'requested'])) {
|
|
|
|
if (unfollowModal) {
|
|
|
|
dispatch(openModal('UNFOLLOW', {
|
|
|
|
account,
|
|
|
|
}))
|
|
|
|
} else {
|
|
|
|
dispatch(unfollowAccount(account.get('id')))
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dispatch(followAccount(account.get('id')))
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onBlock (account) {
|
|
|
|
if (account.getIn(['relationship', 'blocking'])) {
|
|
|
|
dispatch(unblockAccount(account.get('id')))
|
|
|
|
} else {
|
|
|
|
dispatch(blockAccount(account.get('id')))
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onMute (account) {
|
|
|
|
if (account.getIn(['relationship', 'muting'])) {
|
|
|
|
dispatch(unmuteAccount(account.get('id')))
|
|
|
|
} else {
|
|
|
|
dispatch(initMuteModal(account))
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
onMuteNotifications (account, notifications) {
|
|
|
|
dispatch(muteAccount(account.get('id'), notifications))
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
Account.propTypes = {
|
|
|
|
account: ImmutablePropTypes.map.isRequired,
|
|
|
|
onFollow: PropTypes.func.isRequired,
|
|
|
|
onBlock: PropTypes.func.isRequired,
|
|
|
|
onMute: PropTypes.func.isRequired,
|
|
|
|
onMuteNotifications: PropTypes.func,
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
isHidden: PropTypes.bool,
|
|
|
|
actionIcon: PropTypes.string,
|
|
|
|
actionTitle: PropTypes.string,
|
|
|
|
onActionClick: PropTypes.func,
|
|
|
|
compact: PropTypes.bool,
|
|
|
|
expanded: PropTypes.bool,
|
|
|
|
showDismiss: PropTypes.bool,
|
|
|
|
dismissAction: PropTypes.func,
|
|
|
|
withBio: PropTypes.bool,
|
2020-09-14 17:47:46 +01:00
|
|
|
isCard: PropTypes.bool,
|
2020-08-18 01:57:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export default injectIntl(connect(makeMapStateToProps, mapDispatchToProps)(Account))
|