import axios from 'axios' import ImmutablePropTypes from 'react-immutable-proptypes' import ImmutablePureComponent from 'react-immutable-pure-component' import { defineMessages, injectIntl, FormattedMessage } from 'react-intl' import classNames from 'classnames/bind' import { followAccount, unfollowAccount, blockAccount, unblockAccount, } from '../actions/accounts' import { openPopover, closePopover } from '../actions/popover' import { initReport } from '../actions/reports' import { openModal } from '../actions/modal' import { unfollowModal, me } from '../initial_state' import Avatar from './avatar' import Image from './image' import Text from './text' import Button from './button' import DisplayName from './display_name' import TabBar from './tab_bar' const cx = classNames.bind(_s) const messages = defineMessages({ follow: { id: 'follow', defaultMessage: 'Follow' }, unfollow: { id: 'unfollow', defaultMessage: 'Unfollow' }, requested: { id: 'requested', defaultMessage: 'Requested' }, unblock: { id: 'unblock', defaultMessage: 'Unblock' }, followers: { id: 'account.followers', defaultMessage: 'Followers' }, follows: { id: 'account.follows', defaultMessage: 'Follows' }, profile: { id: 'account.profile', defaultMessage: 'Profile' }, }) const mapStateToProps = state => { return { } } const mapDispatchToProps = (dispatch, { intl }) => ({ openProfileOptionsPopover(props) { console.log("props:", props) dispatch(openPopover('PROFILE_OPTIONS', props)) }, onFollow(account) { if (account.getIn(['relationship', 'following']) || account.getIn(['relationship', 'requested'])) { if (unfollowModal) { dispatch(openModal('UNFOLLOW', { accountId: account.get('id'), })); } 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(openModal('BLOCK_ACCOUNT', { accountId: account.get('id'), })); } }, onRepostToggle(account) { if (account.getIn(['relationship', 'showing_reblogs'])) { dispatch(followAccount(account.get('id'), false)); } else { dispatch(followAccount(account.get('id'), true)); } }, }); export default @connect(mapStateToProps, mapDispatchToProps) @injectIntl class ProfileHeader extends ImmutablePureComponent { static propTypes = { account: ImmutablePropTypes.map, intl: PropTypes.object.isRequired, onFollow: PropTypes.func.isRequired, onBlock: PropTypes.func.isRequired, openProfileOptionsPopover: PropTypes.func.isRequired, } handleOpenMore = () => { const { openProfileOptionsPopover, account } = this.props openProfileOptionsPopover({ targetRef: this.openMoreNode, position: 'top', account: this.props.account, }) } handleFollow = () => { this.props.onFollow(this.props.account) } handleBlock = () => { this.props.onBlock(this.props.account) } // : todo : makeInfo() { const { account, intl } = this.props; let info = []; if (!account || !me) return info; if (me !== account.get('id') && account.getIn(['relationship', 'followed_by'])) { info.push({intl.formatMessage(messages.accountFollowsYou)}); } else if (me !== account.get('id') && account.getIn(['relationship', 'blocking'])) { info.push({intl.formatMessage(messages.accountBlocked)}); } if (me !== account.get('id') && account.getIn(['relationship', 'muting'])) { info.push({intl.formatMessage(messages.accountMuted)}); } else if (me !== account.get('id') && account.getIn(['relationship', 'domain_blocking'])) { info.push({intl.formatMessage(messages.domainBlocked)}); } return info; }; setOpenMoreNodeRef = (n) => { this.openMoreNode = n } render() { const { account, intl } = this.props const tabs = !account ? null : [ { to: `/${account.get('acct')}`, title: 'Timeline', }, { to: `/${account.get('acct')}/comments`, title: 'Comments', }, { to: `/${account.get('acct')}/media`, title: 'Media', }, { to: '', title: 'More', }, ] const headerSrc = !!account ? account.get('header') : '' const headerMissing = headerSrc.indexOf('/headers/original/missing.png') > -1 || !headerSrc const avatarContainerClasses = cx({ circle: 1, marginTopNeg75PX: !headerMissing, borderColorWhite: 1, border2PX: 1, }) const avatarSize = headerMissing ? '75' : '150' let buttonText = '' let buttonOptions = {} if (!account) { console.log("no account") } else { if (!account.get('relationship')) { console.log("no relationship") // Wait until the relationship is loaded } else if (account.getIn(['relationship', 'requested'])) { buttonText = intl.formatMessage(messages.requested) buttonOptions = { narrow: true, onClick: this.handleFollow, color: 'primary', backgroundColor: 'tertiary', } } else if (!account.getIn(['relationship', 'blocking'])) { const isFollowing = account.getIn(['relationship', 'following']) const isBlockedBy = account.getIn(['relationship', 'blocked_by']) buttonText = intl.formatMessage(isFollowing ? messages.unfollow : messages.follow) buttonOptions = { narrow: true, onClick: this.handleFollow, color: 'primary', backgroundColor: 'tertiary', disabled: isBlockedBy, } } else if (account.getIn(['relationship', 'blocking'])) { buttonText = intl.formatMessage(messages.unblock) buttonOptions = { narrow: true, onClick: this.handleBlock, color: 'primary', backgroundColor: 'tertiary', } } else { console.log("no nothin") } // if (account.get('id') !== me && account.get('relationship', null) !== null) { // const following = account.getIn(['relationship', 'following']) // const requested = account.getIn(['relationship', 'requested']) // const blocking = account.getIn(['relationship', 'blocking']) // if (requested || blocking) { // buttonText = intl.formatMessage(requested ? messages.requested : messages.unblock) // buttonOptions = { // narrow: true, // onClick: requested ? this.handleFollow : this.handleBlock, // color: 'primary', // backgroundColor: 'tertiary', // } // } else if (!account.get('moved') || following) { // buttonOptions = { // narrow: true, // outline: !following, // color: !following ? 'brand' : 'white', // backgroundColor: !following ? 'none' : 'brand', // onClick: this.handleFollow, // } // buttonText = intl.formatMessage(following ? messages.unfollow : messages.follow) // } else { // console.log("SHOW ELSE") // } // } } console.log("buttonOptions:", buttonText, buttonOptions) // : todo : "follows you", "mutual follow" return (