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

Function useOnPostClick

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

Source from the content-addressed store, hash-verified

96}
97
98export 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) =>

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