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

Function usePostActions

packages/shared/src/hooks/post/usePostActions.ts:23–71  ·  view source on GitHub ↗
({ post }: { post?: Post })

Source from the content-addressed store, hash-verified

21};
22
23export const usePostActions = ({ post }: { post?: Post }): UsePostActions => {
24 const client = useQueryClient();
25 const postId = post?.id;
26 const key = useMemo(() => {
27 if (!postId) {
28 return [RequestKey.PostActions, 'missing-post'];
29 }
30
31 return generateQueryKey(RequestKey.PostActions, { id: postId });
32 }, [postId]);
33
34 const queryFn = useCallback((): PostActionData => {
35 return defaultPostActionData;
36 }, []);
37
38 const { data } = useQuery({
39 queryKey: key,
40 queryFn,
41 initialData: queryFn,
42 staleTime: Infinity,
43 gcTime: Infinity,
44 enabled: !!postId,
45 ...disabledRefetch,
46 });
47 const actionData = data ?? queryFn();
48
49 const onInteract = useCallback(
50 (interaction: PostActionData['interaction']) => {
51 if (!postId) {
52 return;
53 }
54
55 client.setQueryData<PostActionData>(key, {
56 interaction,
57 previousInteraction:
58 actionData.interaction === interaction
59 ? 'none'
60 : actionData.interaction,
61 });
62 },
63 [client, key, actionData.interaction, postId],
64 );
65
66 return {
67 interaction: actionData.interaction,
68 previousInteraction: actionData.previousInteraction,
69 onInteract,
70 };
71};

Callers 5

FreeformList.tsxFile · 0.90
PostContentShareFunction · 0.90
PostReminderOptionsFunction · 0.90
useCardCoverFunction · 0.90
useCardActionsFunction · 0.90

Calls 1

generateQueryKeyFunction · 0.90

Tested by

no test coverage detected