import React, { useEffect, useState } from 'react' import { Bookmark, ArrowRight, MapPin } from 'lucide-react' import { useNavigate } from 'react-router-dom' import { useTranslation } from '../../i18n' import { collectionsApi } from '../../api/collections' import { entityGradient } from '../../utils/gradients' import type { Collection } from '@trek/shared' /** * Dashboard sidebar widget — a glassy `.tool` card that surfaces the user's * saved-place LISTS as compact colour-washed badges (a mini version of the * collections hero): each badge shows the list's cover image (tinted with its * colour) or a colour gradient, its name and place count, and jumps to that * list. Fetches only list() (per-list place_count), so no N+1. */ export default function CollectionsWidget({ onOpen }: { onOpen: () => void }): React.ReactElement { const { t } = useTranslation() const navigate = useNavigate() const [lists, setLists] = useState([]) const [loading, setLoading] = useState(true) useEffect(() => { let cancelled = false ;(async () => { try { const data = await collectionsApi.list() if (!cancelled) setLists(data.collections) } catch { if (!cancelled) setLists([]) } finally { if (!cancelled) setLoading(false) } })() return () => { cancelled = true } }, []) return (
{t('collections.widget.title')}
{loading ? null : lists.length === 0 ? (
{t('collections.widget.empty')}
) : (
{lists.slice(0, 6).map(list => ( ))}
)}
) }