This repository has been archived on 2026-11-17. You can view files and clone it, but cannot push or open issues or pull requests.
gitgram-ai/gitgram/web/components/SeenTracker.tsx
caelum0x bfc29616b7 feat: round-7 external harvest (18 features, all products green)
- gitgram-web (4): external link-preview/unfurl cards, rich inline embed players
  (YouTube/Twitch/Spotify/Vimeo)
- gitgram-backend (1): natural-language feed filtering (preferredLangOnly) + Post.contentLanguage
- gitgram-mobile (4): notification grouping/aggregation, shared timeAgo util
- aitm-api (7): GitNexus graph-RAG query + context retrieval endpoints (flagship surface)
- aitm-mcp (2): beads_claim atomic claim-for-work tool + brief-deps projection

Note: gitgram-backend adds Post.contentLanguage — run prisma migrate at deploy.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-28 19:17:27 +03:00

51 lines
1.3 KiB
TypeScript

'use client'
import { useEffect, useRef } from 'react'
interface SeenTrackerProps {
/** Called once when the element has been sufficiently visible. */
onSeen: () => void
children: React.ReactNode
className?: string
/** Fraction of the element that must be visible to count as seen (0-1). */
threshold?: number
}
/**
* Wraps feed content and fires `onSeen` once when it scrolls into view, using
* an IntersectionObserver. Used to emit the "seen" feed-feedback signal so the
* ranker can learn which posts the viewer actually looked at.
*/
export function SeenTracker({ onSeen, children, className, threshold = 0.5 }: SeenTrackerProps) {
const ref = useRef<HTMLDivElement>(null)
const firedRef = useRef(false)
useEffect(() => {
const el = ref.current
if (!el || firedRef.current) return
const observer = new IntersectionObserver(
(entries) => {
for (const entry of entries) {
if (entry.isIntersecting && !firedRef.current) {
firedRef.current = true
onSeen()
observer.disconnect()
}
}
},
{ threshold },
)
observer.observe(el)
return () => observer.disconnect()
}, [onSeen, threshold])
return (
<div ref={ref} className={className}>
{children}
</div>
)
}
export default SeenTracker