import { Button } from '@/components/ui/button'; import { CoursePlayerProps } from '@/types/page'; import { usePage } from '@inertiajs/react'; import { Download, Eye } from 'lucide-react'; const Resource = () => { const { props } = usePage(); const resources = (props.watching as SectionLesson).resources; // Helper to handle file download const handleDownload = async (resource: LessonResource, e: React.MouseEvent) => { e.preventDefault(); try { // For non-link resources, use the download endpoint const url = route('resources.download', resource.id); window.open(url, '_blank'); } catch (error) { // Fallback to direct download if the endpoint fails window.open(resource.resource, '_blank'); } }; return (
{resources.map((resource: LessonResource) => resource.type === 'link' ? (
{resource.title.slice(0, 50) + (resource.title.length > 50 ? '...' : '')}
) : (
handleDownload(resource, e)}> {resource.title.slice(0, 50) + (resource.title.length > 50 ? '...' : '')}
), )}
); }; export default Resource;