Files
marco/app/modifiers/observe-intersection.js
T
raucao 9a5517012c Fix activity feed first load, sender names, and infinite scroll
- Treat contacts as loaded only once the kind 3 event exists, so the first
  home window is fetched with the follow list, and re-fetch the initial window
  when contacts arrive late.
- Resolve sender kind 0 profiles from the user's relays and the content's
  origin relays, and retry unresolved senders after the first load.
- Auto-load older pages while the end sentinel stays visible via a service-side
  loop, guarded by hasMore and a fetch lock, with an epoch token so a mode
  switch invalidates in-flight fetches.
- Deduplicate zap entries across window re-fetches.
2026-11-17 00:31:06 +04:00

42 lines
1.2 KiB
JavaScript

import { modifier } from 'ember-modifier';
// Reports the element's intersection state to `onVisibilityChange(isVisible)`
// whenever it changes (and once on first observe). `disabled` removes the
// observer entirely.
//
// This only reports visibility; it deliberately does not call a "load" callback
// on every intersection. The decision to load lives in the activity service,
// which keeps loading while the sentinel is visible instead of relying on
// modifier re-runs and IntersectionObserver initial callbacks.
export default modifier((element, [onVisibilityChange, disabled]) => {
if (disabled || typeof onVisibilityChange !== 'function') return;
let observer;
let cancelled = false;
let lastVisible = null;
observer = new IntersectionObserver(
(entries) => {
if (cancelled) return;
const isVisible = !!entries[0]?.isIntersecting;
if (isVisible === lastVisible) return;
lastVisible = isVisible;
onVisibilityChange(isVisible);
},
{
root: null,
rootMargin: '200px',
threshold: 0,
}
);
observer.observe(element);
return () => {
cancelled = true;
if (observer) {
observer.disconnect();
}
};
});