'use client' import { ErrorBoundaryCustom } from '@thedaviddias/design-system/error-boundary' import { ToggleGroup, ToggleGroupItem } from '@thedaviddias/design-system/toggle-group' import { Clock, SortAsc } from 'lucide-react' import { useEffect, useState } from 'react' import { EmptyState } from '@/components/empty-state' import { LLMGrid } from '@/components/llm/llm-grid' import { useWebsiteFilters } from '@/hooks/use-website-filters' import type { WebsiteMetadata } from '@/lib/content-loader' import { getRoute } from '@/lib/routes' interface HomepageWebsitesListProps { initialWebsites: WebsiteMetadata[] } /** * Type guard to validate WebsiteMetadata objects */ function isValidWebsite(website: any): website is WebsiteMetadata { const isValid = website && typeof website.slug === 'string' && typeof website.name === 'string' && typeof website.description === 'string' && typeof website.website === 'string' && typeof website.llmsUrl === 'string' && typeof website.category === 'string' && typeof website.publishedAt === 'string' return isValid } /** * Homepage version of websites list without category filters (since they're in sidebar) * Shows content type filters and sort options in a clean grid layout */ export function HomepageWebsitesList({ initialWebsites }: HomepageWebsitesListProps) { const [websites, setWebsites] = useState(initialWebsites) const { sortBy, setSortBy } = useWebsiteFilters({ includeCategory: false // Don't handle category on homepage }) // Update filtered and sorted websites when filters or initial websites change useEffect(() => { let filteredWebsites = [...initialWebsites] // Sort by selected criteria if (sortBy === 'latest') { filteredWebsites.sort( (a, b) => new Date(b.publishedAt).getTime() - new Date(a.publishedAt).getTime() ) } else if (sortBy === 'name') { filteredWebsites.sort((a, b) => a.name.localeCompare(b.name)) } // Validate websites after all filtering and sorting const validWebsites = filteredWebsites.filter(isValidWebsite) setWebsites(validWebsites) }, [initialWebsites, sortBy]) return (