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

Function usePostFeedback

packages/shared/src/hooks/usePostFeedback.ts:27–114  ·  view source on GitHub ↗
({
  post,
}: UsePostFeedbackProps = {})

Source from the content-addressed store, hash-verified

25}
26
27export const usePostFeedback = ({
28 post,
29}: UsePostFeedbackProps = {}): UsePostFeedback => {
30 const client = useQueryClient();
31 const { queryKey: feedQueryKey, items } = useContext(ActiveFeedContext);
32 const { logEvent } = useLogContext();
33
34 const isMyFeed = useMemo(() => {
35 return feedQueryKey?.some((item) => item === SharedFeedPage.MyFeed);
36 }, [feedQueryKey]);
37
38 const dismissFeedbackMutation = useMutation({
39 mutationFn: () => dismissPostFeedback(post.id),
40
41 onMutate: () => {
42 if (!post) {
43 return;
44 }
45
46 logEvent({
47 event_name: LogEvent.ClickDismissFeedback,
48 });
49
50 const mutationHandler = (postItem: Post) => {
51 return {
52 userState: {
53 ...postItem.userState,
54 flags: {
55 ...postItem.userState?.flags,
56 feedbackDismiss: true,
57 },
58 },
59 };
60 };
61
62 if (feedQueryKey) {
63 const postIndex = items.findIndex(
64 (item) =>
65 (item.type === 'post' && item.post.id === post.id) ||
66 (item.type === 'ad' && item.ad.data?.post?.id === post.id),
67 );
68
69 if (postIndex === -1) {
70 return;
71 }
72
73 const item = items[postIndex];
74 if (item.type === 'post') {
75 const updateFeedPost = updateCachedPagePost(feedQueryKey, client);
76 const updateFeedPostCache = optimisticPostUpdateInFeed(
77 items,
78 updateFeedPost,
79 mutationHandler,
80 );
81 updateFeedPostCache({ index: postIndex });
82 } else if (isBoostedPostAd(item)) {
83 updateFeedAndAdsCache(
84 post.id,

Callers 5

ArticleList.tsxFile · 0.90
ArticleGrid.tsxFile · 0.90
FeedbackListFunction · 0.90
FeedbackGridFunction · 0.90

Calls 9

useLogContextFunction · 0.90
dismissPostFeedbackFunction · 0.90
updateCachedPagePostFunction · 0.90
isBoostedPostAdFunction · 0.90
updateFeedAndAdsCacheFunction · 0.90
updatePostCacheFunction · 0.90
logEventFunction · 0.85
mutationHandlerFunction · 0.70

Tested by

no test coverage detected