( items: FeedItem[], updatePost: (page: number, index: number, post: Post) => void, columns: number, feedName: string, ranking?: string, eventName = 'click', feedQueryKey?: unknown[], )
| 19 | ) => Promise<void>; |
| 20 | |
| 21 | export 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 | } |
no test coverage detected