import { useEffect, useState } from 'react' import type { ReactNode } from 'react' import { Link } from 'react-router-dom' import type { SiteContent } from '../content' import { StoreLink } from './StoreLink' type TabKey = 'downloads' | 'books' | 'recommended' interface Props { content: SiteContent downloadPath: (resourceId: string) => string // Shown when there are no downloads, books or recommended resources at all fallback: ReactNode } // A description that stays short in the grid; long ones get a Read more toggle function ClampedText({ text, className, lines = 3, threshold = 150 }: { text: string; className: string; lines?: number; threshold?: number }) { const [open, setOpen] = useState(false) const long = text.length > threshold return ( <>
{text}
{long && ( )} > ) } export function ResourcesHub({ content, downloadPath, fallback }: Props) { const links = content.customLinks ?? [] // Ask for name and email before sending visitors to Amazon / Apple Books (on unless switched off in the admin) const gated = content.gateStoreLinks !== false const resources = links.filter(l => l.placement === 'resources') const books = links.filter(l => l.placement === 'books') const recommended = links.filter(l => l.placement === 'recommended') const featured: { key: string; to: string; title: string; description: string; image: string; alt: string }[] = [] if (content.studyGuideTitle) { featured.push({ key: 'primary', to: '/downloads/primary-guide', title: content.studyGuideTitle, description: content.studyGuideDescription ?? '', image: content.seriesImageUrl || '/images/titus-cover.png', alt: content.seriesTitle, }) } if (content.secondSeries?.guide?.title) { featured.push({ key: 'second', to: '/downloads/second-guide', title: content.secondSeries.guide.title, description: content.secondSeries.guide.description ?? '', image: content.secondSeries.imageUrl ?? '', alt: content.secondSeries.title, }) } const counts: Record{f.description}
} Download free guide โ{r.description}
} {(r.tags ?? []).length > 0 && {(r.tags ?? []).join(' ยท ')}} Open download โNo downloads tagged "{activeTag}".
)} > )} {tab === 'books' && ({item.description}
} Visit โ