({
items,
updatePost,
columns,
feedName,
ranking,
eventName = 'click',
feedQueryKey,
searchLogExtra,
}: UseFeedOnPostClickProps)
| 31 | } |
| 32 | |
| 33 | export 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 | await onPostClick({ post, row, column, index, optional }); |
| 56 | |
| 57 | if (optional?.skipPostUpdate) { |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | const item = items[index]; |
| 62 | if (item.type === 'post') { |
| 63 | updatePost(item.page, item.index, { ...post, read: true }); |
| 64 | } else if (isBoostedPostAd(item) && feedQueryKey) { |
| 65 | updateFeedAndAdsCache(post.id, feedQueryKey, queryClient, { |
| 66 | read: true, |
| 67 | }); |
| 68 | } |
| 69 | }, |
| 70 | // @NOTE see https://dailydotdev.atlassian.net/l/cp/dK9h1zoM |
| 71 | // eslint-disable-next-line react-hooks/exhaustive-deps |
| 72 | [items, updatePost, columns, feedName, ranking, searchLogExtra], |
| 73 | ); |
| 74 | } |
no test coverage detected