import { useState, useEffect } from 'react' import { Link } from 'react-router-dom' import Navbar from '../components/Navbar' import Footer from '../components/Footer' import DynamicPageRenderer from '../components/DynamicPageRenderer' import { API_BASE, type Category, type Article, type PageSection } from '../types' export default function ScentGuidePage() { const [categories, setCategories] = useState([]) const [articles, setArticles] = useState([]) const [cmsSections, setCmsSections] = useState([]) useEffect(() => { fetch(`${API_BASE}/categories`).then(r => r.json()).then(setCategories).catch(console.error) fetch(`${API_BASE}/articles?publishedOnly=true`).then(r => r.json()).then(setArticles).catch(console.error) }, []) useEffect(() => { fetch(`${API_BASE}/pages/scent-guide-layout`) .then((r) => { if (!r.ok) throw new Error('Page not found'); return r.json(); }) .then((data) => { if (data && data.sections) { setCmsSections(data.sections); } }) .catch((err) => { console.log('Scent guide dynamic layout sections not loaded:', err.message); }); }, []) const announcementSections = cmsSections.filter(s => s.isActive && s.type.toUpperCase() === 'ANNOUNCEMENT_BAR'); const heroSections = cmsSections.filter(s => s.isActive && (s.type.toUpperCase() === 'HERO' || s.type.toUpperCase() === 'BANNER')); const bottomSections = cmsSections.filter(s => s.isActive && s.type.toUpperCase() !== 'ANNOUNCEMENT_BAR' && s.type.toUpperCase() !== 'HERO' && s.type.toUpperCase() !== 'BANNER'); return (
{announcementSections.length > 0 && ( )} {/* Header */} {heroSections.length > 0 ? (
) : (

Journal

Scent Guide

Explore our collection of articles, guides, and sensory knowledge.

)}
{articles.length === 0 ? (
Articles coming soon. Check back later!
) : (
{articles.map(article => (
{article.coverImage ? ( {article.title} ) : (
No Image
)}

{new Date(article.createdAt).toLocaleDateString()}

{article.title}

{/* Remove HTML tags for purely excerpt preview */}
))}
)}
{bottomSections.length > 0 && ( )}
) }