| 1 | import React, { useEffect } from 'react'
|
|---|
| 2 | import { Users, BookOpen, Heart, MessageCircle } from 'lucide-react'
|
|---|
| 3 | import { useAuthStore } from '../../store/authStore'
|
|---|
| 4 | import { useStoryStore } from '../../store/storyStore'
|
|---|
| 5 |
|
|---|
| 6 | export const PlatformStats: React.FC = () => {
|
|---|
| 7 | const { allUsers, fetchAllUsers } = useAuthStore()
|
|---|
| 8 | const { stories, fetchStories } = useStoryStore()
|
|---|
| 9 |
|
|---|
| 10 | useEffect(() => { fetchStories(); fetchAllUsers() }, [])
|
|---|
| 11 |
|
|---|
| 12 | const totalLikes = stories.reduce((acc, s) => acc + s.total_likes, 0)
|
|---|
| 13 | const totalComments = stories.reduce((acc, s) => acc + s.total_comments, 0)
|
|---|
| 14 | const published = stories.filter(s => s.status === 'published').length
|
|---|
| 15 |
|
|---|
| 16 | const stats = [
|
|---|
| 17 | { icon: <Users size={24} className="text-blue-300" />, label: 'Total Users', value: allUsers.length, color: 'bg-blue-500/20', change: `${allUsers.filter(u => u.role === 'writer').length} writers` },
|
|---|
| 18 | { icon: <BookOpen size={24} className="text-violet-300" />, label: 'Total Stories', value: stories.length, color: 'bg-violet-500/20', change: `${published} published` },
|
|---|
| 19 | { icon: <Heart size={24} className="text-rose-300" />, label: 'Total Likes', value: totalLikes.toLocaleString(), color: 'bg-rose-500/20', change: 'Across all stories' },
|
|---|
| 20 | { icon: <MessageCircle size={24} className="text-emerald-300" />, label: 'Total Comments', value: totalComments.toLocaleString(), color: 'bg-emerald-500/20', change: 'Platform-wide' },
|
|---|
| 21 | ]
|
|---|
| 22 |
|
|---|
| 23 | return (
|
|---|
| 24 | <div className="grid grid-cols-2 md:grid-cols-4 gap-4">
|
|---|
| 25 | {stats.map(stat => (
|
|---|
| 26 | <div key={stat.label} className="bg-slate-800 border border-slate-700 rounded-2xl p-6">
|
|---|
| 27 | <div className={`w-12 h-12 rounded-xl ${stat.color} flex items-center justify-center mb-4`}>
|
|---|
| 28 | {stat.icon}
|
|---|
| 29 | </div>
|
|---|
| 30 | <p className="text-3xl font-bold text-white mb-1">{stat.value}</p>
|
|---|
| 31 | <p className="text-slate-400 text-sm font-medium">{stat.label}</p>
|
|---|
| 32 | <p className="text-slate-600 text-xs mt-1">{stat.change}</p>
|
|---|
| 33 | </div>
|
|---|
| 34 | ))}
|
|---|
| 35 | </div>
|
|---|
| 36 | )
|
|---|
| 37 | }
|
|---|