diff --git a/app/javascript/gabsocial/components/popover/user_info_popover.js b/app/javascript/gabsocial/components/popover/user_info_popover.js index 66c8a7f2..ec8947a0 100644 --- a/app/javascript/gabsocial/components/popover/user_info_popover.js +++ b/app/javascript/gabsocial/components/popover/user_info_popover.js @@ -6,6 +6,7 @@ import ImmutablePureComponent from 'react-immutable-pure-component' import { NavLink } from 'react-router-dom' import { FormattedMessage } from 'react-intl' import { makeGetAccount } from '../../selectors' +import { fetchRelationships } from '../../actions/accounts' import { shortNumberFormat } from '../../utils/numbers' import { me } from '../../initial_state' import PopoverLayout from './popover_layout' @@ -16,6 +17,24 @@ import UserStat from '../user_stat' class UserInfoPopover extends ImmutablePureComponent { + componentDidMount() { + this.checkRelationships(this.props.account) + } + + componentDidUpdate(prevProps) { + const { account } = this.props + if (prevProps.account !== account) { + this.checkRelationships(account) + } + } + + checkRelationships = (account) => { + if (!account) return + if (!account.get('relationship')) { + this.props.onFetchRelationships(account.get('id')) + } + } + render() { const { account, isXS } = this.props @@ -72,10 +91,16 @@ const mapStateToProps = (state, props) => ({ account: makeGetAccount()(state, props.accountId), }) +const mapDispatchToProps = (dispatch) => ({ + onFetchRelationships(accountId) { + dispatch(fetchRelationships([accountId])) + }, +}) + UserInfoPopover.propTypes = { account: ImmutablePropTypes.map, accountId: PropTypes.string.isRequired, isXS: PropTypes.bool, } -export default connect(mapStateToProps)(UserInfoPopover) \ No newline at end of file +export default connect(mapStateToProps, mapDispatchToProps)(UserInfoPopover) \ No newline at end of file diff --git a/app/javascript/gabsocial/components/profile_header.js b/app/javascript/gabsocial/components/profile_header.js index 9aeb962d..c9682bff 100644 --- a/app/javascript/gabsocial/components/profile_header.js +++ b/app/javascript/gabsocial/components/profile_header.js @@ -12,6 +12,9 @@ import { MODAL_EDIT_PROFILE, BREAKPOINT_EXTRA_SMALL, } from '../constants' +import { + fetchRelationships, +} from '../actions/accounts' import { addShortcut, removeShortcut, @@ -41,6 +44,24 @@ class ProfileHeader extends ImmutablePureComponent { stickied: false, } + componentDidMount() { + this.checkRelationships(this.props.account) + } + + componentDidUpdate(prevProps) { + const { account } = this.props + if (prevProps.account !== account) { + this.checkRelationships(account) + } + } + + checkRelationships = (account) => { + if (!account) return + if (!account.get('relationship')) { + this.props.onFetchRelationships(account.get('id')) + } + } + handleOnEditProfile = () => { this.props.onEditProfile() } @@ -447,6 +468,9 @@ const mapDispatchToProps = (dispatch) => ({ onCreateChatConversation(accountId, routerHistory) { dispatch(createChatConversation(accountId, routerHistory)) }, + onFetchRelationships(accountId) { + dispatch(fetchRelationships([accountId])) + }, }); ProfileHeader.propTypes = {