source: chapterx-frontend/src/components/admin/PlatformStats.tsx@ a8f4a2d

main
Last change on this file since a8f4a2d was a8f4a2d, checked in by kikisrbinoska <srbinoskakristina07@…>, 11 days ago

Fixed views count

  • Property mode set to 100644
File size: 2.2 KB
Line 
1import React, { useEffect } from 'react'
2import { Users, BookOpen, Heart, MessageCircle, Eye } from 'lucide-react'
3import { useAuthStore } from '../../store/authStore'
4import { useStoryStore } from '../../store/storyStore'
5
6export 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 totalViews = stories.reduce((acc, s) => acc + s.total_views, 0)
15 const published = stories.filter(s => s.status === 'published').length
16
17 const stats = [
18 { 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` },
19 { icon: <BookOpen size={24} className="text-violet-300" />, label: 'Total Stories', value: stories.length, color: 'bg-violet-500/20', change: `${published} published` },
20 { icon: <Eye size={24} className="text-cyan-300" />, label: 'Total Views', value: totalViews.toLocaleString(), color: 'bg-cyan-500/20', change: 'Chapter reads' },
21 { icon: <Heart size={24} className="text-rose-300" />, label: 'Total Likes', value: totalLikes.toLocaleString(), color: 'bg-rose-500/20', change: 'Across all stories' },
22 { icon: <MessageCircle size={24} className="text-emerald-300" />, label: 'Total Comments', value: totalComments.toLocaleString(), color: 'bg-emerald-500/20', change: 'Platform-wide' },
23 ]
24
25 return (
26 <div className="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-4">
27 {stats.map(stat => (
28 <div key={stat.label} className="bg-slate-800 border border-slate-700 rounded-2xl p-6">
29 <div className={`w-12 h-12 rounded-xl ${stat.color} flex items-center justify-center mb-4`}>
30 {stat.icon}
31 </div>
32 <p className="text-3xl font-bold text-white mb-1">{stat.value}</p>
33 <p className="text-slate-400 text-sm font-medium">{stat.label}</p>
34 <p className="text-slate-600 text-xs mt-1">{stat.change}</p>
35 </div>
36 ))}
37 </div>
38 )
39}
Note: See TracBrowser for help on using the repository browser.