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

Function useFeedOnPostClick

packages/shared/src/hooks/feed/useFeedOnPostClick.ts:33–80  ·  view source on GitHub ↗
({
  items,
  updatePost,
  columns,
  feedName,
  ranking,
  eventName = 'click',
  feedQueryKey,
  searchLogExtra,
}: UseFeedOnPostClickProps)

Source from the content-addressed store, hash-verified

31}
32
33export default function useFeedOnPostClick({
34 items,
35 updatePost,
36 columns,
37 feedName,
38 ranking,
39 eventName = 'click',
40 feedQueryKey,
41 searchLogExtra,
42}: UseFeedOnPostClickProps): FeedPostClick {
43 const queryClient = useQueryClient();
44 const onPostClick = useOnPostClick({
45 eventName,
46 columns,
47 feedName,
48 ranking,
49 searchLogExtra,
50 });
51
52 return useMemo(
53 () =>
54 async (post, index, row, column, optional): Promise<void> => {
55 const item = items[index];
56 await onPostClick({
57 post,
58 row,
59 column,
60 index,
61 optional: { ...optional, is_ad: isBoostedPostAd(item) },
62 });
63
64 if (optional?.skipPostUpdate) {
65 return;
66 }
67
68 if (item.type === 'post') {
69 updatePost(item.page, item.index, { ...post, read: true });
70 } else if (isBoostedPostAd(item) && feedQueryKey) {
71 updateFeedAndAdsCache(post.id, feedQueryKey, queryClient, {
72 read: true,
73 });
74 }
75 },
76 // @NOTE see https://dailydotdev.atlassian.net/l/cp/dK9h1zoM
77 // eslint-disable-next-line react-hooks/exhaustive-deps
78 [items, updatePost, columns, feedName, ranking, searchLogExtra],
79 );
80}

Callers 1

FeedFunction · 0.85

Calls 4

isBoostedPostAdFunction · 0.90
updateFeedAndAdsCacheFunction · 0.90
useOnPostClickFunction · 0.85
updatePostFunction · 0.50

Tested by

no test coverage detected