import classNames from 'classnames'; import PropTypes from 'prop-types'; import React, { useEffect, useState } from 'react'; import ImmutablePropTypes from 'react-immutable-proptypes'; import { useIntl } from 'react-intl'; import { usePopper } from 'react-popper'; import { useSelector, useDispatch } from 'react-redux'; import { useHistory } from 'react-router-dom'; import { fetchRelationships } from 'soapbox/actions/accounts'; import { closeProfileHoverCard, updateProfileHoverCard, } from 'soapbox/actions/profile_hover_card'; import Badge from 'soapbox/components/badge'; import ActionButton from 'soapbox/features/ui/components/action_button'; import BundleContainer from 'soapbox/features/ui/containers/bundle_container'; import { UserPanel } from 'soapbox/features/ui/util/async-components'; import { makeGetAccount } from 'soapbox/selectors'; import { showProfileHoverCard } from './hover_ref_wrapper'; import { Card, CardBody, Stack, Text } from './ui'; const getAccount = makeGetAccount(); const getBadges = (account) => { const badges = []; if (account.admin) { badges.push(); } else if (account.moderator) { badges.push(); } if (account.getIn(['patron', 'is_patron'])) { badges.push(); } return badges; }; const handleMouseEnter = (dispatch) => { return e => { dispatch(updateProfileHoverCard()); }; }; const handleMouseLeave = (dispatch) => { return e => { dispatch(closeProfileHoverCard(true)); }; }; export const ProfileHoverCard = ({ visible }) => { const dispatch = useDispatch(); const history = useHistory(); const intl = useIntl(); const [popperElement, setPopperElement] = useState(null); const me = useSelector(state => state.get('me')); const accountId = useSelector(state => state.getIn(['profile_hover_card', 'accountId'])); const account = useSelector(state => accountId && getAccount(state, accountId)); const targetRef = useSelector(state => state.getIn(['profile_hover_card', 'ref', 'current'])); const badges = account ? getBadges(account) : []; useEffect(() => { if (accountId) dispatch(fetchRelationships([accountId])); }, [dispatch, accountId]); useEffect(() => { const unlisten = history.listen(() => { showProfileHoverCard.cancel(); dispatch(closeProfileHoverCard()); }); return () => { unlisten(); }; }, []); const { styles, attributes } = usePopper(targetRef, popperElement); if (!account) return null; const accountBio = { __html: account.get('note_emojified') }; const followedBy = me !== account.get('id') && account.getIn(['relationship', 'followed_by']); return (
{Component => ( } badges={badges} /> )} {account.getIn(['source', 'note'], '').length > 0 && ( )} {followedBy && (
)}
); }; ProfileHoverCard.propTypes = { visible: PropTypes.bool, accountId: PropTypes.string, account: ImmutablePropTypes.record, }; ProfileHoverCard.defaultProps = { visible: true, }; export default ProfileHoverCard;