diff --git a/src/components/pure-status.tsx b/src/components/pure-status.tsx index 4a3328022..7724d5058 100644 --- a/src/components/pure-status.tsx +++ b/src/components/pure-status.tsx @@ -8,7 +8,7 @@ import { Link, useHistory } from 'react-router-dom'; import { mentionCompose } from 'soapbox/actions/compose.ts'; import { openModal } from 'soapbox/actions/modals.ts'; -import { toggleStatusHidden, unfilterStatus } from 'soapbox/actions/statuses.ts'; +import { unfilterStatus } from 'soapbox/actions/statuses.ts'; import TranslateButton from 'soapbox/components/translate-button.tsx'; import { Card } from 'soapbox/components/ui/card.tsx'; import Icon from 'soapbox/components/ui/icon.tsx'; @@ -24,6 +24,7 @@ import { useFavourite } from 'soapbox/hooks/useFavourite.ts'; import { useReblog } from 'soapbox/hooks/useReblog.ts'; import { useReplyCompose } from 'soapbox/hooks/useReplyCompose.ts'; import { useSettings } from 'soapbox/hooks/useSettings.ts'; +import { useStatusHidden } from 'soapbox/hooks/useStatusHidden.ts'; import { makeGetStatus } from 'soapbox/selectors/index.ts'; import { emojifyText } from 'soapbox/utils/emojify.tsx'; import { defaultMediaVisibility, textForScreenReader, getActualStatus } from 'soapbox/utils/status.ts'; @@ -107,6 +108,7 @@ const PureStatus: React.FC = (props) => { const { replyCompose } = useReplyCompose(); const { toggleFavourite } = useFavourite(); const { toggleReblog } = useReblog(); + const { toggleStatusHidden } = useStatusHidden(); // Track height changes we know about to compensate scrolling. useEffect(() => { @@ -211,7 +213,7 @@ const PureStatus: React.FC = (props) => { }; const handleHotkeyToggleHidden = (): void => { - dispatch(toggleStatusHidden(statusImmutable)); // fix later + toggleStatusHidden(status.id); }; const handleHotkeyToggleSensitive = (): void => { diff --git a/src/hooks/useStatusHidden.ts b/src/hooks/useStatusHidden.ts new file mode 100644 index 000000000..a492f450f --- /dev/null +++ b/src/hooks/useStatusHidden.ts @@ -0,0 +1,25 @@ +import { revealStatus as revealStatusAction, hideStatus as hideStatusAction, toggleStatusHidden as toggleStatusHiddenAction } from 'soapbox/actions/statuses.ts'; +import { useAppDispatch } from 'soapbox/hooks/useAppDispatch.ts'; +import { useGetState } from 'soapbox/hooks/useGetState.ts'; + +export function useStatusHidden() { + const getState = useGetState(); + const dispatch = useAppDispatch(); + + const revealStatus = (statusId: string) => { + dispatch(revealStatusAction(statusId)); + }; + + const hideStatus = (statusId: string) => { + dispatch(hideStatusAction(statusId)); + }; + + const toggleStatusHidden = (statusId: string) => { + const status = getState().statuses.get(statusId); + if (status) { + dispatch(toggleStatusHiddenAction(status)); + } + }; + + return { revealStatus, hideStatus, toggleStatusHidden }; +}