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

Function useOnPostClick

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

Source from the content-addressed store, hash-verified

92}
93
94export 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),

Callers 3

BriefListItemFunction · 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