({
eventName = 'go to link',
columns,
feedName,
ranking,
origin,
searchLogExtra,
}: UseOnPostClickProps)
| 97 | } |
| 98 | |
| 99 | export default function useOnPostClick({ |
| 100 | eventName = 'go to link', |
| 101 | columns, |
| 102 | feedName, |
| 103 | ranking, |
| 104 | origin, |
| 105 | searchLogExtra, |
| 106 | }: UseOnPostClickProps): FeedPostClick { |
| 107 | const client = useQueryClient(); |
| 108 | const { logEvent } = useLogContext(); |
| 109 | const { checkReadingStreak } = useReadingStreak(); |
| 110 | const { queryKey: feedQueryKey, items } = useContext(ActiveFeedContext); |
| 111 | const { shouldUseListFeedLayout } = useFeedLayout({ |
| 112 | feedRelated: false, |
| 113 | }); |
| 114 | const postLogEvent = usePostLogEvent(); |
| 115 | |
| 116 | return useMemo( |
| 117 | () => |
| 118 | async ({ post, row, column, index, optional }): Promise<void> => { |
| 119 | logEvent( |
| 120 | postLogEvent(eventName, post, { |
| 121 | columns, |
| 122 | column, |
| 123 | row, |
| 124 | index, |
| 125 | is_ad: optional?.is_ad, |
| 126 | extra: { |
| 127 | ...feedLogExtra( |
| 128 | feedName ?? '', |
| 129 | ranking, |
| 130 | searchLogExtra, |
| 131 | origin, |
| 132 | undefined, |
| 133 | optional?.parent_id, |
| 134 | ).extra, |
| 135 | feedback: post.type === PostType.Article ? true : undefined, |
| 136 | }, |
| 137 | }), |
| 138 | ); |
| 139 | |
| 140 | if (optional?.skipPostUpdate) { |
| 141 | return; |
| 142 | } |
| 143 | |
| 144 | if (!post.read) { |
| 145 | checkReadingStreak(); |
| 146 | } |
| 147 | |
| 148 | if (eventName === 'go to link') { |
| 149 | const mutationHandler = withPostRead; |
| 150 | |
| 151 | if (feedQueryKey) { |
| 152 | const postIndex = items.findIndex( |
| 153 | (item) => |
| 154 | (item.type === 'post' && item.post.id === post.id) || |
| 155 | (item.type === 'ad' && item.ad.data?.post?.id === post.id), |
| 156 | ); |
no test coverage detected