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

Function useFeedOnPostClick

packages/shared/src/hooks/feed/useFeedOnPostClick.ts:21–60  ·  view source on GitHub ↗
(
  items: FeedItem[],
  updatePost: (page: number, index: number, post: Post) => void,
  columns: number,
  feedName: string,
  ranking?: string,
  eventName = 'click',
  feedQueryKey?: unknown[],
)

Source from the content-addressed store, hash-verified

19) => Promise<void>;
20
21export default function useFeedOnPostClick(
22 items: FeedItem[],
23 updatePost: (page: number, index: number, post: Post) => void,
24 columns: number,
25 feedName: string,
26 ranking?: string,
27 eventName = 'click',
28 feedQueryKey?: unknown[],
29): FeedPostClick {
30 const queryClient = useQueryClient();
31 const onPostClick = useOnPostClick({
32 eventName,
33 columns,
34 feedName,
35 ranking,
36 });
37
38 return useMemo(
39 () =>
40 async (post, index, row, column, optional): Promise<void> => {
41 await onPostClick({ post, row, column, optional });
42
43 if (optional?.skipPostUpdate) {
44 return;
45 }
46
47 const item = items[index];
48 if (item.type === 'post') {
49 updatePost(item.page, item.index, { ...post, read: true });
50 } else if (isBoostedPostAd(item) && feedQueryKey) {
51 updateFeedAndAdsCache(post.id, feedQueryKey, queryClient, {
52 read: true,
53 });
54 }
55 },
56 // @NOTE see https://dailydotdev.atlassian.net/l/cp/dK9h1zoM
57 // eslint-disable-next-line react-hooks/exhaustive-deps
58 [items, updatePost, columns, feedName, ranking],
59 );
60}

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