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