import { Skeleton } from '@/components/ui/skeleton' import { useFetchRelayInfo } from '@/hooks' import { toRelay } from '@/lib/link' import { useSmartRelayNavigation } from '@/PageManager' import relayInfoService from '@/services/relay-info.service' import { TAwesomeRelayCollection } from '@/types' import { useEffect, useState } from 'react' import RelaySimpleInfo, { RelaySimpleInfoSkeleton } from '../RelaySimpleInfo' import logger from '@/lib/logger' export default function Explore() { const [collections, setCollections] = useState(null) const [error, setError] = useState(null) useEffect(() => { let cancelled = false let timeoutId: ReturnType | null = null // Add timeout to prevent hanging forever timeoutId = setTimeout(() => { if (!cancelled) { logger.warn('[Explore] Timeout loading relay collections after 10 seconds') setError('Timeout loading relay collections') setCollections([]) // Set empty array to stop showing skeletons } }, 10000) // 10 second timeout logger.debug('[Explore] Fetching awesome relay collections') relayInfoService.getAwesomeRelayCollections() .then((data) => { if (!cancelled) { if (timeoutId) clearTimeout(timeoutId) logger.debug('[Explore] Loaded collections', { count: data?.length || 0 }) setCollections(data || []) } }) .catch((err) => { if (!cancelled) { if (timeoutId) clearTimeout(timeoutId) logger.error('[Explore] Error loading collections', { error: err }) setError(err instanceof Error ? err.message : 'Failed to load relay collections') setCollections([]) // Set empty array to stop showing skeletons } }) return () => { cancelled = true if (timeoutId) clearTimeout(timeoutId) } }, []) if (collections === null) { return (
) } if (error) { return (
Error: {error}
) } if (collections.length === 0) { return (
No relay collections available
) } return (
{collections.map((collection) => ( ))}
) } function RelayCollection({ collection }: { collection: TAwesomeRelayCollection }) { return (
{collection.name}
{collection.relays.map((url) => ( ))}
) } function RelayItem({ url }: { url: string }) { const { navigateToRelay } = useSmartRelayNavigation() const { relayInfo, isFetching } = useFetchRelayInfo(url) if (isFetching) { return } if (!relayInfo) { return null } return (
{ e.stopPropagation() navigateToRelay(toRelay(relayInfo.url)) }} />
) }