import { Head } from '@inertiajs/react'; import { useEffect, useState } from 'react'; import { type BreadcrumbItem } from '@/types'; import AppLayout from '@/layouts/app-layout'; import { Phone, Mail } from 'lucide-react'; import { Link } from '@inertiajs/react'; import { SingleImageLightbox, ImageLightbox } from '@/components/image-lightbox'; import AttachmentsList from '@/components/attachments-list'; const truncateText = (text: string, maxLength: number): string => { if (text.length <= maxLength) return text; return text.slice(0, maxLength) + '…'; }; const getBreadcrumbs = (section: string, slug: string): BreadcrumbItem[] => [ { title: 'Strona Główna', href: '/', }, { title: 'Aktualności', href: '/aktualnosci', }, { title: truncateText(section, 35), href: `/aktualnosci/${slug}`, }, ]; interface Photo { id: number; image_name: string; image_desc: string; image_path: string; created_at: string; updated_at: string; } interface Attachment { id: number; file_name: string; file_path: string; created_at: string; updated_at: string; } interface News { id: number; title: string; slug: string; thumbnail: string; body: string; active: boolean; published_at: string; created_at: string; updated_at: string; user_id: number; photos?: Photo[]; attachments?: Attachment[]; } interface NewsApiResponse { articleNews: Record; } interface NewsPageProps { slug: string; } export default function NewsSlug(props: NewsPageProps) { const { slug } = props; const [news, setNews] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { setLoading(true); fetch(`/api/news?slug=${encodeURIComponent(slug)}`) .then(response => response.json()) .then(data => { setNews(data); setLoading(false); }) .catch(error => { setNews(null); setLoading(false); console.error('Error fetching news:', error); }); }, [slug]); const sectionName = news && Object.values(news.articleNews)[0]?.title || slug.replace(/-/g, ' '); return (
{loading ? (
Wczytywanie zawartości...
) : !news || Object.keys(news.articleNews).length === 0 ? (
Brak artykułów.
) : (
{Object.values(news.articleNews).map((article) => (
{article.thumbnail ? (

{article.title}

Data publikacji: {new Date(article.published_at).toLocaleDateString('pl-PL')}
) : (

{article.title}

Data publikacji: {new Date(article.published_at).toLocaleDateString('pl-PL')}
)} {article.photos && article.photos.length > 0 && (

Galeria

{article.photos.map((photo, index) => ( } initialIndex={index} /> ))}
)}
))}
)}
); }