| 1 | import { useQuery } from '@tanstack/react-query' |
| 2 | import { Link } from 'react-router' |
| 3 | import { Avatar } from '../../components/ui/Avatar' |
| 4 | import { request } from '../../lib/api' |
| 5 | import { FollowButton } from './FollowButton' |
| 6 | |
| 7 | type Suggestion = { handle: string; followers: number } |
| 8 | |
| 9 | export function Suggestions() { |
| 10 | const { data } = useQuery({ |
| 11 | queryKey: ['suggestions'], |
| 12 | queryFn: () => |
| 13 | request<{ users: Suggestion[] }>('/suggestions').then( |
| 14 | (r) => r.users, |
| 15 | ), |
| 16 | }) |
| 17 | if (!data?.length) return null |
| 18 | return ( |
| 19 | <section aria-labelledby="suggest"> |
| 20 | <h2 id="suggest" className="text-sm font-semibold"> |
| 21 | Who to follow |
| 22 | </h2> |
| 23 | <ul className="mt-3 space-y-3"> |
| 24 | {data.map((s) => ( |
| 25 | <li key={s.handle} className="flex items-center gap-3"> |
| 26 | <Avatar handle={s.handle} size={32} /> |
| 27 | <div className="min-w-0 flex-1 text-sm"> |
| 28 | <Link |
| 29 | to={`/u/${s.handle}`} |
| 30 | className="block truncate font-medium hover:underline" |
| 31 | > |
| 32 | @{s.handle} |
| 33 | </Link> |
| 34 | <p className="text-mute"> |
| 35 | {s.followers.toLocaleString('en')} followers |
| 36 | </p> |
| 37 | </div> |
| 38 | <FollowButton handle={s.handle} following={false} /> |
| 39 | </li> |
| 40 | ))} |
| 41 | </ul> |
| 42 | </section> |
| 43 | ) |
| 44 | } |