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

Function onScroll

packages/shared/src/features/patchy/usePatchyAssistant.ts:268–320  ·  view source on GitHub ↗
(event: Event)

Source from the content-addressed store, hash-verified

266 return undefined;
267 }
268 const onScroll = (event: Event) => {
269 lastScrollAtRef.current = Date.now();
270 const session = sessionRef.current;
271 if (
272 !session ||
273 session.isUpvoted ||
274 session.isFinishOffered ||
275 Date.now() - session.openedAt < MIN_READ_MS
276 ) {
277 return;
278 }
279 const target = event.target as Element | Document | null;
280 let scroller: Element | null = null;
281 if (
282 target instanceof Element &&
283 target.classList.contains('post-modal-overlay')
284 ) {
285 scroller = target;
286 } else if (
287 target === document &&
288 window.location.pathname.startsWith('/posts/')
289 ) {
290 scroller = document.scrollingElement;
291 }
292 if (!scroller || scroller.scrollHeight <= scroller.clientHeight) {
293 return;
294 }
295 const progress =
296 (scroller.scrollTop + scroller.clientHeight) / scroller.scrollHeight;
297 if (progress < FINISHED_AT) {
298 return;
299 }
300 session.isFinishOffered = true;
301 const now = Date.now();
302 queue({
303 kind: 'finished',
304 text: 'Done! Worth an upvote?',
305 primary: 'Upvote',
306 secondary: 'Nah',
307 isOverModal: true,
308 notBefore: now + 600,
309 expiresAt: now + 30000,
310 isStillUseful: () =>
311 !session.isUpvoted &&
312 getPatchyCurrentPost(client, session.post).userState?.vote !==
313 UserVote.Up,
314 onPrimary: () =>
315 toggleUpvote({
316 payload: getPatchyCurrentPost(client, session.post) as Post,
317 origin: Origin.Patchy,
318 }),
319 });
320 };
321 window.addEventListener('scroll', onScroll, {
322 capture: true,
323 passive: true,

Callers 3

FeaturedMosaicFunction · 0.50
useWidgetScrollFunction · 0.50
FeedWidgetRailHeaderFunction · 0.50

Calls 3

getPatchyCurrentPostFunction · 0.90
toggleUpvoteFunction · 0.85
nowMethod · 0.80

Tested by

no test coverage detected