import React, { useState, useEffect, useCallback } from 'react'; import { MediaList } from '../components/MediaList'; import { MediaItem } from '../api/jellyfin'; import { Loader } from '../components/Loader'; import { usePageTitle } from '../context/PageTitleContext/PageTitleContext'; import { useNavigate, useParams } from 'react-router-dom'; interface SectionData { title: string; description?: string; items: MediaItem[]; } export const SectionMore: React.FC = () => { const { setPageTitle } = usePageTitle(); const { section } = useParams<{ section: string }>(); const navigate = useNavigate(); const [sectionData, setSectionData] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const fetchSectionData = useCallback(async () => { setLoading(true); setError(null); try { // Determine the correct backend URL based on environment let fetchUrl; // Check if we're on the live site if (window.location.hostname === 'music.samcloud.ca') { // Use relative URL for live site (will use the same domain with reverse proxy) fetchUrl = `/api/discover/${section}`; } else { // Use development backend URL for localhost const backendUrl = import.meta.env.VITE_BACKEND_URL || 'http://localhost:5140'; fetchUrl = `${backendUrl}/api/discover/${section}`; } console.log('Fetching section data from:', fetchUrl); const response = await fetch(fetchUrl); if (!response.ok) { const errorData = await response.json(); throw new Error(errorData.error || `HTTP error! status: ${response.status}`); } const data = await response.json(); console.log('Section data received:', data); setSectionData(data); setPageTitle(data.title); } catch (e: any) { console.error(`Failed to fetch ${section} data:`, e); setError(e.message || `Failed to fetch ${section} content.`); } finally { setLoading(false); } }, [section, setPageTitle]); useEffect(() => { if (section) { fetchSectionData(); } }, [section, fetchSectionData]); if (loading) { return (

{section ? section.replace(/-/g, ' ').replace(/\b\w/g, l => l.toUpperCase()) : 'Section'}

); } if (error) { return (

{section ? section.replace(/-/g, ' ').replace(/\b\w/g, l => l.toUpperCase()) : 'Section'}

{error}

We're having trouble loading this section. Please try again later.

); } if (!sectionData) { return (

{section ? section.replace(/-/g, ' ').replace(/\b\w/g, l => l.toUpperCase()) : 'Section'}

No data available for this section.

); } return (

{sectionData.title}

{sectionData.description &&

{sectionData.description}

}
); };