| // src/components/article/AuthorCard.tsx | |
| "use client"; | |
| import { useState } from "react"; | |
| import { Link } from "react-router-dom"; | |
| import { Author } from "@/types"; | |
| import { UserCheck, UserPlus, Users, FileText, Calendar } from "lucide-react"; | |
| interface AuthorCardProps { | |
| author: Author; | |
| currentUsername?: string; | |
| isFollowing: boolean; | |
| onFollowToggle: () => void; | |
| articleCount?: number; // optional, can be passed from parent | |
| joinDate?: string; // optional join date | |
| } | |
| export function AuthorCard({ | |
| author, | |
| currentUsername, | |
| isFollowing, | |
| onFollowToggle, | |
| articleCount, | |
| joinDate, | |
| }: AuthorCardProps) { | |
| const [loading, setLoading] = useState(false); | |
| const displayName = author.fullName || author.username; | |
| const initial = displayName[0].toUpperCase(); | |
| const handleToggle = async () => { | |
| setLoading(true); | |
| try { | |
| await onFollowToggle(); | |
| } finally { | |
| setLoading(false); | |
| } | |
| }; | |
| const formatDate = (dateStr?: string) => { | |
| if (!dateStr) return ""; | |
| const date = new Date(dateStr); | |
| if (isNaN(date.getTime())) return ""; | |
| return date.toLocaleDateString(undefined, { year: "numeric", month: "long" }); | |
| }; | |
| return ( | |
| <div className="mt-8 bg-white dark:bg-gray-800 rounded-2xl shadow-md p-6 border border-gray-100 dark:border-gray-700"> | |
| <div className="flex flex-col sm:flex-row gap-5 items-start"> | |
| {/* Avatar */} | |
| <Link to={`/users/${author.username}`} className="shrink-0"> | |
| <div className="w-16 h-16 rounded-full bg-gradient-to-br from-primary to-secondary text-white flex items-center justify-center text-2xl font-bold shadow-md transition-transform hover:scale-105"> | |
| {initial} | |
| </div> | |
| </Link> | |
| <div className="flex-1 w-full"> | |
| <div className="flex flex-wrap justify-between items-start gap-3"> | |
| <div> | |
| <Link | |
| to={`/users/${author.username}`} | |
| className="text-lg font-semibold hover:text-primary transition" | |
| > | |
| {displayName} | |
| </Link> | |
| <p className="text-sm text-gray-500 dark:text-gray-400">@{author.username}</p> | |
| <div className="flex flex-wrap gap-3 mt-2 text-sm text-gray-500"> | |
| <div className="flex items-center gap-1"> | |
| <Users className="w-4 h-4" /> | |
| {author.followersCount || 0} followers | |
| </div> | |
| {articleCount !== undefined && ( | |
| <div className="flex items-center gap-1"> | |
| <FileText className="w-4 h-4" /> | |
| {articleCount} articles | |
| </div> | |
| )} | |
| {joinDate && ( | |
| <div className="flex items-center gap-1"> | |
| <Calendar className="w-4 h-4" /> | |
| Joined {formatDate(joinDate)} | |
| </div> | |
| )} | |
| </div> | |
| </div> | |
| {/* Follow button (only for other users) */} | |
| {currentUsername && currentUsername !== author.username && ( | |
| <button | |
| onClick={handleToggle} | |
| disabled={loading} | |
| className={`flex items-center gap-2 px-4 py-2 rounded-full text-sm font-medium transition ${ | |
| isFollowing | |
| ? "bg-gray-100 dark:bg-gray-700 text-gray-800 dark:text-gray-200 hover:bg-gray-200 dark:hover:bg-gray-600" | |
| : "bg-primary text-white hover:bg-primary/90" | |
| } disabled:opacity-50`} | |
| aria-label={isFollowing ? "Unfollow" : "Follow"} | |
| > | |
| {loading ? ( | |
| <div className="w-4 h-4 border-2 border-current border-t-transparent rounded-full animate-spin" /> | |
| ) : isFollowing ? ( | |
| <UserCheck className="w-4 h-4" /> | |
| ) : ( | |
| <UserPlus className="w-4 h-4" /> | |
| )} | |
| {isFollowing ? "Following" : "Follow"} | |
| </button> | |
| )} | |
| {!currentUsername && ( | |
| <Link | |
| to="/login" | |
| className="flex items-center gap-2 rounded-full bg-primary px-4 py-2 text-sm font-medium text-white hover:bg-primary/90" | |
| > | |
| <UserPlus className="w-4 h-4" /> | |
| Sign in to follow | |
| </Link> | |
| )} | |
| </div> | |
| {/* Bio (if available) */} | |
| {author.bio && ( | |
| <p className="mt-3 text-sm text-gray-600 dark:text-gray-300 border-l-4 border-primary pl-3"> | |
| {author.bio} | |
| </p> | |
| )} | |
| </div> | |
| </div> | |
| </div> | |
| ); | |
| } | |
Xet Storage Details
- Size:
- 4.73 kB
- Xet hash:
- 932adbb3c3fa3e5ab87e88418113b89d82e121c1042a32438ac6e46cfaac6704
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.