import { Skeleton } from '@/components/ui/skeleton' import { useFetchRelayInfo } from '@/hooks' import { toRelay } from '@/lib/link' import { recommendRelaysByLanguage } from '@/lib/relay' import { cn } from '@/lib/utils' import { useSecondaryPage } from '@/PageManager' import { useDeepBrowsing } from '@/providers/DeepBrowsingProvider' import relayInfoService from '@/services/relay-info.service' import { TAwesomeRelayCollection } from '@/types' import { useEffect, useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' import RelaySimpleInfo, { RelaySimpleInfoSkeleton } from '../RelaySimpleInfo' export default function Explore() { const { t, i18n } = useTranslation() const [collections, setCollections] = useState(null) const recommendedRelays = useMemo(() => { const lang = i18n.language const relays = recommendRelaysByLanguage(lang) return relays }, [i18n.language]) useEffect(() => { relayInfoService.getAwesomeRelayCollections().then(setCollections) }, []) if (!collections && recommendedRelays.length === 0) { return (
) } return (
{recommendedRelays.length > 0 && ( )} {collections && collections.map((collection) => ( ))}
) } function RelayCollection({ collection }: { collection: TAwesomeRelayCollection }) { const { deepBrowsing } = useDeepBrowsing() return (
{collection.name}
{collection.relays.map((url) => ( ))}
) } function RelayItem({ url }: { url: string }) { const { push } = useSecondaryPage() const { relayInfo, isFetching } = useFetchRelayInfo(url) if (isFetching) { return } if (!relayInfo) { return null } return ( { e.stopPropagation() push(toRelay(relayInfo.url)) }} /> ) }