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