import { useCallback, useEffect, useState } from 'react'; import { channelDirectory as $channelDirectoryContent } from '../../content'; import { getAvatarSrc } from '../../helpers'; import { getLiveChannels } from '../../api/channels'; import { useNotif } from '../../contexts/Notification'; import ChannelCard from '../../components/ChannelCard'; import GridLayout from './GridLayout'; import useForceLoader from '../../hooks/useForceLoader'; const $content = $channelDirectoryContent.live_streams_section; const $channelPageNotifications = $channelDirectoryContent.notification; const LiveStreamsSection = () => { const [data, setData] = useState(); const [error, setError] = useState(); const { notifyError } = useNotif(); const isLoadingForced = useForceLoader(); const { channels: liveChannels } = data || {}; const hasLiveChannels = !!liveChannels?.length; const isLoading = (!error && !data) || isLoadingForced; const getSectionData = useCallback(async () => { setData(undefined); setError(undefined); const { result, error: fetchError } = await getLiveChannels(); setData(result); setError(fetchError); if (fetchError) notifyError( $channelDirectoryContent.notification.error.error_loading_streams ); }, [notifyError]); useEffect(() => { getSectionData(); }, [getSectionData]); return ( {hasLiveChannels && liveChannels.map((data) => { const { color, username } = data; return ( ); })} ); }; export default LiveStreamsSection;