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

Function useReportPost

packages/shared/src/hooks/useReportPost.ts:33–87  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

31}
32
33export default function useReportPost(): UseReportPostRet {
34 const { user, showLogin } = useContext(AuthContext);
35 const { requestMethod } = useRequestProtocol();
36 const request = requestMethod ?? gqlRequest;
37 const { mutateAsync: reportPostAsync } = useMutation<
38 void,
39 unknown,
40 ReportPostProps
41 >({
42 mutationFn: (variables) => request(REPORT_POST_MUTATION, variables),
43 });
44
45 const { mutateAsync: hidePostAsync } = useMutation<void, unknown, string>({
46 mutationFn: (id) => gqlClient.request(HIDE_POST_MUTATION, { id }),
47 });
48
49 const { mutateAsync: unhidePostAsync } = useMutation<void, unknown, string>({
50 mutationFn: (id) => gqlClient.request(UNHIDE_POST_MUTATION, { id }),
51 });
52
53 const reportPost = async (params: ReportPostProps) => {
54 if (!user) {
55 showLogin({ trigger: AuthTriggers.ReportPost });
56 return { successful: false };
57 }
58
59 await reportPostAsync(params);
60
61 return { successful: true };
62 };
63
64 const hidePost = async (id: string) => {
65 if (!user) {
66 showLogin({ trigger: AuthTriggers.HidePost });
67 return { successful: false };
68 }
69
70 await hidePostAsync(id);
71
72 return { successful: true };
73 };
74
75 const unhidePost = async (id: string) => {
76 if (!user) {
77 showLogin({ trigger: AuthTriggers.HidePost });
78 return { successful: false };
79 }
80
81 await unhidePostAsync(id);
82
83 return { successful: true };
84 };
85
86 return { reportPost, hidePost, unhidePost };
87}

Callers 2

ReportPostModalFunction · 0.85
useHidePostFunction · 0.85

Calls 1

useRequestProtocolFunction · 0.90

Tested by

no test coverage detected