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

Function onScroll

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

Source from the content-addressed store, hash-verified

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

Callers 2

FeaturedMosaicFunction · 0.50
useWidgetScrollFunction · 0.50

Calls 2

getPatchyCurrentPostFunction · 0.90
toggleUpvoteFunction · 0.85

Tested by

no test coverage detected