import { useState } from 'react'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'; import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; import { Skeleton } from '@/components/ui/skeleton'; import { useFollowing, useFollowers, useFollowActions } from '@/hooks/useFollowing'; import { useAuthor } from '@/hooks/useAuthor'; import { useCurrentUser } from '@/hooks/useCurrentUser'; import { genUserName } from '@/lib/genUserName'; import { Users, UserPlus, UserMinus, Loader2 } from 'lucide-react'; import { useTranslation } from '@/contexts/language'; function FollowingUserCard({ pubkey, onUnfollow }: { pubkey: string; onUnfollow: (pubkey: string) => void }) { const author = useAuthor(pubkey); const metadata = author.data?.metadata; const displayName = metadata?.name ?? genUserName(pubkey); const [isUnfollowing, setIsUnfollowing] = useState(false); const { t } = useTranslation(); const handleUnfollow = async () => { setIsUnfollowing(true); await onUnfollow(pubkey); setIsUnfollowing(false); }; return (
{displayName.slice(0, 2).toUpperCase()}
{displayName}
{metadata?.nip05 && (
{metadata.nip05}
)} {!metadata?.nip05 && (
{pubkey.slice(0, 8)}...{pubkey.slice(-8)}
)}
); } function FollowerUserCard({ pubkey }: { pubkey: string }) { const author = useAuthor(pubkey); const metadata = author.data?.metadata; const displayName = metadata?.name ?? genUserName(pubkey); return (
{displayName.slice(0, 2).toUpperCase()}
{displayName}
{metadata?.nip05 && (
{metadata.nip05}
)} {!metadata?.nip05 && (
{pubkey.slice(0, 8)}...{pubkey.slice(-8)}
)}
); } export function FollowListManager() { const { user } = useCurrentUser(); const { t } = useTranslation(); const { data: following = [], isLoading: followingLoading } = useFollowing(); const { data: followers = [], isLoading: followersLoading } = useFollowers(); const { unfollow, followByIdentifier, isFollowing } = useFollowActions(); const [followInput, setFollowInput] = useState(''); const handleFollow = async (e: React.FormEvent) => { e.preventDefault(); if (!followInput.trim()) return; await followByIdentifier(followInput.trim()); setFollowInput(''); }; if (!user) { return null; } return ( {t('settingsUi.followList.title')} {t('settingsUi.followList.desc')} {t('settingsUi.followList.following', { count: following.length })} {t('settingsUi.followList.followers', { count: followers.length })} {/* Add Follow Input */}
setFollowInput(e.target.value)} className="flex-1" disabled={isFollowing} />

{t('settingsUi.followList.followHint')}

{/* Following List */} {followingLoading ? (
{Array.from({ length: 3 }).map((_, i) => (
))}
) : following.length > 0 ? (
{following.map((pubkey) => ( ))}
) : (

{t('settingsUi.followList.notFollowing')}

{t('settingsUi.followList.notFollowingHint')}

)} {/* Trust Info */} {following.length > 0 && (

{t('settingsUi.followList.trustActiveStrong')} {t('settingsUi.followList.trustActive')}

)}
{followersLoading ? (
{Array.from({ length: 3 }).map((_, i) => (
))}
) : followers.length > 0 ? (
{followers.map((pubkey) => ( ))}
) : (

{t('settingsUi.followList.noFollowers')}

{t('settingsUi.followList.noFollowersHint')}

)}
{/* Info Card */} {t('settingsUi.followList.howTitle')}

{t('settingsUi.followList.verifiedStrong')} {t('settingsUi.followList.verifiedDesc')}

{t('settingsUi.followList.trustedStrong')} {t('settingsUi.followList.trustedDesc')}

{t('settingsUi.followList.unverifiedStrong')} {t('settingsUi.followList.unverifiedDesc')}

{t('settingsUi.followList.tip')}

); }