import NormalFeed from '@/components/NormalFeed' import { Button } from '@/components/ui/button' import { usePrimaryPage } from '@/PageManager' import { useFeed } from '@/providers/FeedProvider' import { useFollowList } from '@/providers/FollowListProvider' import { useNostr } from '@/providers/NostrProvider' import client from '@/services/client.service' import { TFeedSubRequest } from '@/types' import { Compass, Search, UserPlus } from 'lucide-react' import { useEffect, useRef, useState } from 'react' import { useTranslation } from 'react-i18next' export default function FollowingFeed() { const { t } = useTranslation() const { pubkey } = useNostr() const { followingSet } = useFollowList() const { navigate } = usePrimaryPage() const { markFeedLoaded } = useFeed() const [subRequests, setSubRequests] = useState([]) const [hasFollowings, setHasFollowings] = useState(null) const [refreshCount, setRefreshCount] = useState(0) const initializedRef = useRef(false) useEffect(() => { if (initializedRef.current) return async function init() { if (!pubkey) { setSubRequests([]) setHasFollowings(null) return } const followings = await client.fetchFollowings(pubkey) setHasFollowings(followings.length > 0) setSubRequests(await client.generateSubRequestsForPubkeys([pubkey, ...followings], pubkey)) if (followings.length) { initializedRef.current = true } } init() }, [pubkey, followingSet, refreshCount]) // Show empty state when user has no followings useEffect(() => { if (hasFollowings === false) markFeedLoaded() }, [hasFollowings, markFeedLoaded]) if (hasFollowings === false && subRequests.length > 0) { return (

{t('Welcome to Smesh!')}

{t( 'Your feed is empty because you are not following anyone yet. Start by exploring interesting content and following users you like!' )}

) } return ( { initializedRef.current = false setRefreshCount((count) => count + 1) }} onInitialLoad={markFeedLoaded} isMainFeed /> ) }