From 0292e4f42893958f62ec0e7e2215c744a4019a43 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 20 Jun 2022 17:04:34 -0500 Subject: [PATCH] StatusHoverCard: fix lint stuff, cleanup --- app/soapbox/components/status-hover-card.tsx | 55 +++++++++----------- 1 file changed, 24 insertions(+), 31 deletions(-) diff --git a/app/soapbox/components/status-hover-card.tsx b/app/soapbox/components/status-hover-card.tsx index e438834b2d..c0d9c803b4 100644 --- a/app/soapbox/components/status-hover-card.tsx +++ b/app/soapbox/components/status-hover-card.tsx @@ -1,40 +1,18 @@ import classNames from 'classnames'; -import React, { useEffect, useState } from 'react'; -import { FormattedMessage } from 'react-intl'; +import React, { useEffect, useState, useCallback } from 'react'; import { usePopper } from 'react-popper'; import { useHistory } from 'react-router-dom'; -import { fetchRelationships } from 'soapbox/actions/accounts'; import { closeStatusHoverCard, updateStatusHoverCard, } from 'soapbox/actions/status-hover-card'; -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 { fetchStatus } from 'soapbox/actions/statuses'; import StatusContainer from 'soapbox/containers/status_container'; import { useAppSelector, useAppDispatch } from 'soapbox/hooks'; -import { makeGetStatus } from 'soapbox/selectors'; -import { fetchStatus } from 'soapbox/actions/statuses'; import { showStatusHoverCard } from './hover-status-wrapper'; -import { Card, CardBody, Stack, Text } from './ui'; - -import type { AppDispatch } from 'soapbox/store'; - -const getStatus = makeGetStatus(); - -const handleMouseEnter = (dispatch: AppDispatch): React.MouseEventHandler => { - return () => { - dispatch(updateStatusHoverCard()); - }; -}; - -const handleMouseLeave = (dispatch: AppDispatch): React.MouseEventHandler => { - return () => { - dispatch(closeStatusHoverCard(true)); - }; -}; +import { Card, CardBody } from './ui'; interface IStatusHoverCard { visible: boolean, @@ -48,11 +26,14 @@ export const StatusHoverCard: React.FC = ({ visible = true }) const [popperElement, setPopperElement] = useState(null); const statusId: string | undefined = useAppSelector(state => state.status_hover_card.statusId || undefined); + const status = useAppSelector(state => state.statuses.get(statusId!)); const targetRef = useAppSelector(state => state.status_hover_card.ref?.current); useEffect(() => { - dispatch(fetchStatus(statusId)); - }, [dispatch, statusId]) + if (!status) { + dispatch(fetchStatus(statusId)); + } + }, [statusId, status]); useEffect(() => { const unlisten = history.listen(() => { @@ -66,9 +47,21 @@ export const StatusHoverCard: React.FC = ({ visible = true }) }, []); const { styles, attributes } = usePopper(targetRef, popperElement, { - placement: 'top' + placement: 'top', }); + const handleMouseEnter = useCallback((): React.MouseEventHandler => { + return () => { + dispatch(updateStatusHoverCard()); + }; + }, []); + + const handleMouseLeave = useCallback((): React.MouseEventHandler => { + return () => { + dispatch(closeStatusHoverCard(true)); + }; + }, []); + if (!statusId) return null; const renderStatus = (statusId: string) => { @@ -85,15 +78,15 @@ export const StatusHoverCard: React.FC = ({ visible = true }) return (