Hovercard: clear when card is unhovered

This commit is contained in:
Alex Gleason 2020-09-10 22:08:17 -05:00
parent 4630a5cd04
commit d8ea37bf5e
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
3 changed files with 23 additions and 5 deletions

View File

@ -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,6 +23,12 @@ 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();
@ -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'>

View File

@ -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() {

View File

@ -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;
}