({
post,
origin = Origin.PostContextMenu,
}: UseHidePostProps)
| 62 | }; |
| 63 | |
| 64 | export const useHidePost = ({ |
| 65 | post, |
| 66 | origin = Origin.PostContextMenu, |
| 67 | }: UseHidePostProps): UseHidePost => { |
| 68 | const { hidePost, unhidePost } = useReportPost(); |
| 69 | const { onShowPanel, onClose } = useBlockPostPanel(post); |
| 70 | const { logEvent } = useLogContext(); |
| 71 | const postLogEvent = usePostLogEvent(); |
| 72 | const { displayToast } = useToastNotification(); |
| 73 | const { items, onRemovePost, logOpts } = useContext(ActiveFeedContext); |
| 74 | const { feedId: customFeedId } = useCustomFeed(); |
| 75 | const { onBlockTags, onUnblockTags, onBlockSource, onUnblockSource } = |
| 76 | useTagAndSource({ |
| 77 | origin, |
| 78 | postId: post.id, |
| 79 | shouldInvalidateQueries: false, |
| 80 | feedId: customFeedId, |
| 81 | }); |
| 82 | |
| 83 | const postIndex = useMemo( |
| 84 | () => |
| 85 | items.findIndex( |
| 86 | (item) => item.type === 'post' && item.post.id === post.id, |
| 87 | ), |
| 88 | [items, post.id], |
| 89 | ); |
| 90 | |
| 91 | const onHide = useCallback(async () => { |
| 92 | const { successful } = await hidePost(post.id); |
| 93 | |
| 94 | if (!successful) { |
| 95 | return false; |
| 96 | } |
| 97 | |
| 98 | logEvent( |
| 99 | postLogEvent(LogEvent.HidePost, post, { |
| 100 | extra: { origin }, |
| 101 | ...logOpts, |
| 102 | }), |
| 103 | ); |
| 104 | |
| 105 | onShowPanel({ mode: 'hide' }); |
| 106 | return true; |
| 107 | }, [hidePost, post, logEvent, postLogEvent, origin, logOpts, onShowPanel]); |
| 108 | |
| 109 | const onUnhide = useCallback(async () => { |
| 110 | const { successful } = await unhidePost(post.id); |
| 111 | |
| 112 | if (!successful) { |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | logEvent( |
| 117 | postLogEvent(LogEvent.HidePostUndo, post, { |
| 118 | ...logOpts, |
| 119 | }), |
| 120 | ); |
| 121 | onClose(true); |
no test coverage detected