Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
File size: 9,517 Bytes
a8fb296 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | /**
* Following lists (Leaders / Charities / Tags) — used under Settings → Person (#674).
* Moved from Profile so following is managed in Settings tabs.
*/
import { useState } from 'react'
import { useQuery } from '@tanstack/react-query'
import { Tab } from '@headlessui/react'
import {
UserIcon,
BuildingLibraryIcon,
HeartIcon,
} from '@heroicons/react/24/outline'
import api from '../../lib/api'
import { formatCityState } from '../../utils/formatters'
import FollowButton from '../FollowButton'
interface Leader {
id: number
name: string
slug: string
title?: string
photo_url?: string
office?: string
city?: string
state?: string
follower_count: number
is_verified: boolean
}
interface Organization {
master_org_id: string
name: string
description?: string
logo_url?: string
org_type?: string
city?: string
state?: string
follower_count: number
is_verified?: boolean
}
interface Tag {
tag_id: string
label?: string
description?: string
category?: string
breadcrumb?: string
follower_count: number
}
function classNames(...classes: string[]) {
return classes.filter(Boolean).join(' ')
}
export default function SettingsFollowing() {
const [selectedTab, setSelectedTab] = useState(0)
const { data: leadersFollowing } = useQuery<Leader[]>({
queryKey: ['following', 'leaders'],
queryFn: async () => (await api.get('/social/following/leaders')).data,
})
const { data: orgsFollowing } = useQuery<Organization[]>({
queryKey: ['following', 'organizations'],
queryFn: async () => (await api.get('/social/following/organizations')).data,
})
const { data: tagsFollowing } = useQuery<Tag[]>({
queryKey: ['following', 'tags'],
queryFn: async () => (await api.get('/social/following/tags')).data,
})
const tabCls = ({ selected }: { selected: boolean }) =>
classNames(
'px-3 py-2 font-medium text-sm border-b-2 transition-colors whitespace-nowrap',
selected
? 'border-[#354F52] text-[#354F52]'
: 'border-transparent text-gray-500 hover:text-gray-700',
)
return (
<div>
<h2 className="text-lg font-semibold text-gray-900 mb-1">Following</h2>
<p className="text-sm text-gray-500 mb-4">
People, charities, and tags you follow
</p>
<Tab.Group selectedIndex={selectedTab} onChange={setSelectedTab}>
<Tab.List className="flex gap-1 border-b border-gray-200 mb-4 overflow-x-auto">
<Tab className={tabCls}>
<span className="inline-flex items-center gap-1.5">
<UserIcon className="h-4 w-4" />
Leaders ({leadersFollowing?.length ?? 0})
</span>
</Tab>
<Tab className={tabCls}>
<span className="inline-flex items-center gap-1.5">
<BuildingLibraryIcon className="h-4 w-4" />
Charities ({orgsFollowing?.length ?? 0})
</span>
</Tab>
<Tab className={tabCls}>
<span className="inline-flex items-center gap-1.5">
<HeartIcon className="h-4 w-4" />
Tags ({tagsFollowing?.length ?? 0})
</span>
</Tab>
</Tab.List>
<Tab.Panels>
<Tab.Panel>
{!leadersFollowing?.length ? (
<Empty
icon={<UserIcon className="h-12 w-12 mx-auto text-gray-300 mb-3" />}
message="You're not following any leaders yet"
href="/people"
linkLabel="Find leaders to follow →"
/>
) : (
<div className="grid grid-cols-1 gap-3">
{leadersFollowing.map((leader) => (
<div
key={leader.id}
className="flex items-start gap-3 p-3 border border-gray-200 rounded-lg"
>
{leader.photo_url ? (
<img
src={leader.photo_url}
alt={leader.name}
className="h-12 w-12 rounded-full object-cover"
/>
) : (
<div
className="h-12 w-12 rounded-full flex items-center justify-center text-white font-bold"
style={{ backgroundColor: '#354F52' }}
>
{leader.name.charAt(0)}
</div>
)}
<div className="flex-1 min-w-0">
<h3 className="font-semibold text-sm" style={{ color: '#354F52' }}>
{leader.name}
{leader.is_verified && <span className="ml-1 text-blue-500">✓</span>}
</h3>
{leader.title && <p className="text-xs text-gray-600">{leader.title}</p>}
{leader.city && leader.state && (
<p className="text-xs text-gray-400">
{formatCityState(leader.city, leader.state)}
</p>
)}
</div>
<FollowButton
type="leader"
id={leader.id}
initialFollowing={true}
initialCount={leader.follower_count}
showCount={false}
compact={true}
/>
</div>
))}
</div>
)}
</Tab.Panel>
<Tab.Panel>
{!orgsFollowing?.length ? (
<Empty
icon={<BuildingLibraryIcon className="h-12 w-12 mx-auto text-gray-300 mb-3" />}
message="You're not following any charities yet"
href="/nonprofits"
linkLabel="Find charities to follow →"
/>
) : (
<div className="grid grid-cols-1 gap-3">
{orgsFollowing.map((org) => (
<div
key={org.master_org_id}
className="flex items-start gap-3 p-3 border border-gray-200 rounded-lg"
>
{org.logo_url ? (
<img
src={org.logo_url}
alt={org.name}
className="h-12 w-12 rounded object-contain"
/>
) : (
<div
className="h-12 w-12 rounded flex items-center justify-center text-white font-bold"
style={{ backgroundColor: '#52796F' }}
>
{org.name.charAt(0)}
</div>
)}
<div className="flex-1 min-w-0">
<h3 className="font-semibold text-sm" style={{ color: '#354F52' }}>
{org.name}
</h3>
{org.description && (
<p className="text-xs text-gray-600 line-clamp-2">{org.description}</p>
)}
</div>
<FollowButton
type="organization"
id={org.master_org_id}
initialFollowing={true}
initialCount={org.follower_count}
showCount={false}
compact={true}
/>
</div>
))}
</div>
)}
</Tab.Panel>
<Tab.Panel>
{!tagsFollowing?.length ? (
<Empty
icon={<HeartIcon className="h-12 w-12 mx-auto text-gray-300 mb-3" />}
message="You're not following any tags yet"
href="/"
linkLabel="Explore tags →"
/>
) : (
<div className="grid grid-cols-1 gap-3">
{tagsFollowing.map((tag) => (
<div
key={tag.tag_id}
className="flex items-start justify-between gap-3 p-3 border border-gray-200 rounded-lg"
>
<div className="min-w-0">
<h3 className="font-semibold text-sm" style={{ color: '#354F52' }}>
{tag.label || tag.tag_id}
</h3>
{tag.breadcrumb && (
<p className="text-xs text-gray-400">{tag.breadcrumb}</p>
)}
</div>
<FollowButton
type="tag"
id={tag.tag_id}
initialFollowing={true}
initialCount={tag.follower_count}
showCount={false}
compact={true}
/>
</div>
))}
</div>
)}
</Tab.Panel>
</Tab.Panels>
</Tab.Group>
</div>
)
}
function Empty({
icon,
message,
href,
linkLabel,
}: {
icon: React.ReactNode
message: string
href: string
linkLabel: string
}) {
return (
<div className="text-center py-8">
{icon}
<p className="text-sm text-gray-500">{message}</p>
<a href={href} className="inline-block mt-3 text-sm font-medium text-teal-800 hover:underline">
{linkLabel}
</a>
</div>
)
}
|