MCPcopy Create free account
hub / github.com/dailydotdev/apps / useHidePost

Function useHidePost

packages/shared/src/hooks/post/useHidePost.ts:64–261  ·  view source on GitHub ↗
({
  post,
  origin = Origin.PostContextMenu,
}: UseHidePostProps)

Source from the content-addressed store, hash-verified

62};
63
64export 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);

Callers 2

PostHiddenPanelFunction · 0.90
PostOptionButtonContentFunction · 0.90

Calls 14

useBlockPostPanelFunction · 0.90
useLogContextFunction · 0.90
usePostLogEventFunction · 0.90
useToastNotificationFunction · 0.90
useCustomFeedFunction · 0.90
useReportPostFunction · 0.85
useTagAndSourceFunction · 0.85
hidePostFunction · 0.85
logEventFunction · 0.85
postLogEventFunction · 0.85
unhidePostFunction · 0.85
displayToastFunction · 0.85

Tested by

no test coverage detected