import { Loader2, Star, UserPlus } from 'lucide-react' import { useCallback, useEffect, useState } from 'react' import { t } from '../../i18n' import { getFeed, type FeedEntry } from '../../lib/cloud/social' import { timeAgo } from '../../lib/timeAgo' import { formatRating } from '../../lib/utils' import { useMedia } from '../../store' import Poster from '../Poster' import { LinkArrow, SectionTitle } from '../ui' import Avatar from './Avatar' import { useSocial } from './SocialProvider' const VERB = { finished: 'feed.finished', started: 'feed.started', rewatched: 'feed.rewatched', added: 'feed.added' } as const /** Accueil : ce que regardent mes abonnements. */ export default function FriendsFeed() { const social = useSocial() const { settings } = useMedia() const [entries, setEntries] = useState() const [more, setMore] = useState(false) const [loadingMore, setLoadingMore] = useState(false) const [shown, setShown] = useState(6) const load = useCallback(async () => { try { const list = await getFeed() setEntries(list) setMore(list.length >= 30) } catch { setEntries([]) } }, []) useEffect(() => { if (social.enabled && navigator.onLine) void load() }, [social.enabled, load]) if (!social.enabled) return null const loadMore = async () => { if (!entries) return if (shown < entries.length) return setShown((n) => n + 10) setLoadingMore(true) try { const next = await getFeed(entries[entries.length - 1]?.createdAt) setEntries([...entries, ...next]) setMore(next.length >= 30) setShown((n) => n + 10) } finally { setLoadingMore(false) } } return ( <> {t('social.findFriends')}}>{t('feed.title')} {entries === undefined ? (

{t('social.loading')}

) : entries.length === 0 ? ( ) : ( <> {(shown < entries.length || more) && ( )} )} ) }