From 2e5cc2619dd0ed81f7db15195c612837481d0d1f Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 1 May 2022 13:11:20 -0500 Subject: [PATCH] ProfileHoverCard: convert to tsx --- app/soapbox/components/hover_ref_wrapper.tsx | 3 +- ...e_hover_card.js => profile_hover_card.tsx} | 52 +++++++++---------- app/soapbox/normalizers/account.ts | 2 +- 3 files changed, 26 insertions(+), 31 deletions(-) rename app/soapbox/components/{profile_hover_card.js => profile_hover_card.tsx} (70%) diff --git a/app/soapbox/components/hover_ref_wrapper.tsx b/app/soapbox/components/hover_ref_wrapper.tsx index 239c27580..f1da2e65d 100644 --- a/app/soapbox/components/hover_ref_wrapper.tsx +++ b/app/soapbox/components/hover_ref_wrapper.tsx @@ -20,7 +20,7 @@ interface IHoverRefWrapper { /** Makes a profile hover card appear when the wrapped element is hovered. */ export const HoverRefWrapper: React.FC = ({ accountId, children, inline = false }) => { const dispatch = useDispatch(); - const ref = useRef(); + const ref = useRef(null); const Elem: keyof JSX.IntrinsicElements = inline ? 'span' : 'div'; const handleMouseEnter = () => { @@ -41,7 +41,6 @@ export const HoverRefWrapper: React.FC = ({ accountId, childre return ( { +const getBadges = (account: Account): JSX.Element[] => { const badges = []; if (account.admin) { @@ -43,29 +44,34 @@ const getBadges = (account) => { return badges; }; -const handleMouseEnter = (dispatch) => { - return e => { +const handleMouseEnter = (dispatch: AppDispatch): React.MouseEventHandler => { + return () => { dispatch(updateProfileHoverCard()); }; }; -const handleMouseLeave = (dispatch) => { - return e => { +const handleMouseLeave = (dispatch: AppDispatch): React.MouseEventHandler => { + return () => { dispatch(closeProfileHoverCard(true)); }; }; -export const ProfileHoverCard = ({ visible }) => { - const dispatch = useDispatch(); +interface IProfileHoverCard { + visible: boolean, +} + +/** Popup profile preview that appears when hovering avatars and display names. */ +export const ProfileHoverCard: React.FC = ({ visible = true }) => { + const dispatch = useAppDispatch(); const history = useHistory(); const intl = useIntl(); - const [popperElement, setPopperElement] = useState(null); + 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 me = useAppSelector(state => state.me); + const accountId: string | undefined = useAppSelector(state => state.profile_hover_card.get('accountId', undefined)); + const account = useAppSelector(state => accountId && getAccount(state, accountId)); + const targetRef = useAppSelector(state => state.profile_hover_card.getIn(['ref', 'current']) as Element | null); const badges = account ? getBadges(account) : []; useEffect(() => { @@ -86,8 +92,8 @@ export const ProfileHoverCard = ({ visible }) => { 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']); + const accountBio = { __html: account.note_emojified }; + const followedBy = me !== account.id && account.relationship.get('followed_by') === true; return (
{ )} - {account.getIn(['source', 'note'], '').length > 0 && ( + {account.source.get('note', '').length > 0 && ( )} @@ -134,14 +140,4 @@ export const ProfileHoverCard = ({ visible }) => { ); }; -ProfileHoverCard.propTypes = { - visible: PropTypes.bool, - accountId: PropTypes.string, - account: ImmutablePropTypes.record, -}; - -ProfileHoverCard.defaultProps = { - visible: true, -}; - export default ProfileHoverCard; diff --git a/app/soapbox/normalizers/account.ts b/app/soapbox/normalizers/account.ts index c4a5faffc..f72b18a09 100644 --- a/app/soapbox/normalizers/account.ts +++ b/app/soapbox/normalizers/account.ts @@ -61,7 +61,7 @@ export const AccountRecord = ImmutableRecord({ note_emojified: '', note_plain: '', patron: null as PatronAccount | null, - relationship: ImmutableList>(), + relationship: ImmutableMap(), should_refetch: false, staff: false, });