Hovercard: clear when card is unhovered
This commit is contained in:
parent
4630a5cd04
commit
d8ea37bf5e
|
@ -11,6 +11,7 @@ import Badge from 'soapbox/components/badge';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { fetchRelationships } from 'soapbox/actions/accounts';
|
import { fetchRelationships } from 'soapbox/actions/accounts';
|
||||||
import { usePopper } from 'react-popper';
|
import { usePopper } from 'react-popper';
|
||||||
|
import { clearProfileHoverCard } from 'soapbox/actions/profile_hover_card';
|
||||||
|
|
||||||
const getAccount = makeGetAccount();
|
const getAccount = makeGetAccount();
|
||||||
|
|
||||||
|
@ -22,13 +23,19 @@ const getBadges = (account) => {
|
||||||
return badges;
|
return badges;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleMouseLeave = (dispatch) => {
|
||||||
|
return e => {
|
||||||
|
dispatch(clearProfileHoverCard());
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
export const ProfileHoverCard = ({ visible }) => {
|
export const ProfileHoverCard = ({ visible }) => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
const [popperElement, setPopperElement] = useState(null);
|
const [popperElement, setPopperElement] = useState(null);
|
||||||
|
|
||||||
const accountId = useSelector(state => state.getIn(['profile_hover_card', 'accountId']));
|
const accountId = useSelector(state => state.getIn(['profile_hover_card', 'accountId']));
|
||||||
const account = useSelector(state => accountId && getAccount(state, accountId));
|
const account = useSelector(state => accountId && getAccount(state, accountId));
|
||||||
const targetRef = useSelector(state => state.getIn(['profile_hover_card', 'ref']));
|
const targetRef = useSelector(state => state.getIn(['profile_hover_card', 'ref']));
|
||||||
const badges = account ? getBadges(account) : [];
|
const badges = account ? getBadges(account) : [];
|
||||||
|
|
||||||
|
@ -36,14 +43,21 @@ export const ProfileHoverCard = ({ visible }) => {
|
||||||
if (accountId) dispatch(fetchRelationships([accountId]));
|
if (accountId) dispatch(fetchRelationships([accountId]));
|
||||||
}, [dispatch, accountId]);
|
}, [dispatch, accountId]);
|
||||||
|
|
||||||
const { styles, attributes } = usePopper(targetRef, popperElement);
|
const { styles, attributes } = usePopper(targetRef, popperElement, {
|
||||||
|
modifiers: [{
|
||||||
|
name: 'offset',
|
||||||
|
options: {
|
||||||
|
offset: [-100, 0],
|
||||||
|
},
|
||||||
|
}],
|
||||||
|
});
|
||||||
|
|
||||||
if (!account) return null;
|
if (!account) return null;
|
||||||
const accountBio = { __html: account.get('note_emojified') };
|
const accountBio = { __html: account.get('note_emojified') };
|
||||||
const followedBy = account.getIn(['relationship', 'followed_by']);
|
const followedBy = account.getIn(['relationship', 'followed_by']);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames('profile-hover-card', { 'profile-hover-card--visible': visible })} ref={setPopperElement} style={styles.popper} {...attributes.popper}>
|
<div className={classNames('profile-hover-card', { 'profile-hover-card--visible': visible })} ref={setPopperElement} style={styles.popper} {...attributes.popper} onMouseLeave={handleMouseLeave(dispatch)}>
|
||||||
<div className='profile-hover-card__container'>
|
<div className='profile-hover-card__container'>
|
||||||
{followedBy &&
|
{followedBy &&
|
||||||
<span className='relationship-tag'>
|
<span className='relationship-tag'>
|
||||||
|
|
|
@ -108,7 +108,6 @@ class Status extends ImmutablePureComponent {
|
||||||
state = {
|
state = {
|
||||||
showMedia: defaultMediaVisibility(this.props.status, this.props.displayMedia),
|
showMedia: defaultMediaVisibility(this.props.status, this.props.displayMedia),
|
||||||
statusId: undefined,
|
statusId: undefined,
|
||||||
profileCardVisible: false,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Track height changes we know about to compensate scrolling
|
// Track height changes we know about to compensate scrolling
|
||||||
|
@ -268,7 +267,6 @@ class Status extends ImmutablePureComponent {
|
||||||
handleProfileLeave = e => {
|
handleProfileLeave = e => {
|
||||||
this.showProfileHoverCard.cancel();
|
this.showProfileHoverCard.cancel();
|
||||||
this.props.onClearProfileHoverCard();
|
this.props.onClearProfileHoverCard();
|
||||||
this.setState({ profileCardVisible: false });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_properStatus() {
|
_properStatus() {
|
||||||
|
|
|
@ -125,3 +125,9 @@
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Hide the popper when the reference is hidden */
|
||||||
|
#popper[data-popper-reference-hidden] {
|
||||||
|
visibility: hidden;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue