MCPcopy Create free account
hub / github.com/dailydotdev/apps / useOnPostClick

Function useOnPostClick

packages/shared/src/hooks/useOnPostClick.ts:99–231  ·  view source on GitHub ↗
({
  eventName = 'go to link',
  columns,
  feedName,
  ranking,
  origin,
  searchLogExtra,
}: UseOnPostClickProps)

Source from the content-addressed store, hash-verified

97}
98
99export 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 );

Callers 5

BriefListItemFunction · 0.85
BriefingWidgetFunction · 0.85
useReadArticleFunction · 0.85
useFeedOnPostClickFunction · 0.85

Calls 14

useLogContextFunction · 0.90
useReadingStreakFunction · 0.90
useFeedLayoutFunction · 0.90
usePostLogEventFunction · 0.90
feedLogExtraFunction · 0.90
updateCachedPagePostFunction · 0.90
isBoostedPostAdFunction · 0.90
updateFeedAndAdsCacheFunction · 0.90
logEventFunction · 0.85
postLogEventFunction · 0.85
getFeedQueryKeysFunction · 0.85

Tested by

no test coverage detected