diff --git a/ui/src/views/forum/admin/Dashboard.tsx b/ui/src/views/forum/admin/Dashboard.tsx index 5ce2278e..afb58512 100644 --- a/ui/src/views/forum/admin/Dashboard.tsx +++ b/ui/src/views/forum/admin/Dashboard.tsx @@ -1,22 +1,28 @@ -import React from 'react'; -import { Folder, MessageSquare, FileText, TrendingUp } from 'lucide-react'; -import { ForumCategory, ForumPost, ForumTopic } from '@/proxy/forum/forum'; -import { useLocalization } from '@/utils/hooks/useLocalization'; +import { Folder, MessageSquare, FileText, TrendingUp } from 'lucide-react' +import { ForumCategory, ForumPost, ForumTopic } from '@/proxy/forum/forum' +import { useLocalization } from '@/utils/hooks/useLocalization' +import { formatDistanceToNow } from 'date-fns' interface AdminStatsProps { - categories: ForumCategory[]; - topics: ForumTopic[]; - posts: ForumPost[]; + categories: ForumCategory[] + topics: ForumTopic[] + posts: ForumPost[] +} + +interface Activity { + message: string + color: string + date: Date } export function AdminStats({ categories, topics, posts }: AdminStatsProps) { - const { translate } = useLocalization(); - const totalCategories = categories.length; - const activeCategories = categories.filter(c => c.isActive).length; - const totalTopics = topics.length; - const solvedTopics = topics.filter(t => t.isSolved).length; - const totalPosts = posts.length; - const acceptedAnswers = posts.filter(p => p.isAcceptedAnswer).length; + const { translate } = useLocalization() + const totalCategories = categories.length + const activeCategories = categories.filter((c) => c.isActive).length + const totalTopics = topics.length + const solvedTopics = topics.filter((t) => t.isSolved).length + const totalPosts = posts.length + const acceptedAnswers = posts.filter((p) => p.isAcceptedAnswer).length const stats = [ { @@ -47,20 +53,65 @@ export function AdminStats({ categories, topics, posts }: AdminStatsProps) { icon: TrendingUp, color: 'bg-purple-500', }, - ]; + ] + + const recentActivities: Activity[] = [] + + // Topics -> "New topic created in {categoryName}" + topics.forEach((topic) => { + const category = categories.find((c) => c.id === topic.categoryId) + if (topic.creationTime) { + recentActivities.push({ + message: `New topic created in ${category?.name ?? 'Unknown Category'}`, + color: 'bg-blue-500', + date: new Date(topic.creationTime), + }) + } + }) + + // Posts -> "Post marked as accepted answer" + posts.forEach((post) => { + if (post.isAcceptedAnswer && post.creationTime) { + recentActivities.push({ + message: 'Post marked as accepted answer', + color: 'bg-emerald-500', + date: new Date(post.creationTime), + }) + } + }) + + // Categories -> "New category created: {name}" + categories.forEach((category) => { + if (category.creationTime) { + recentActivities.push({ + message: `New category created: ${category.name}`, + color: 'bg-orange-500', + date: new Date(category.creationTime), + }) + } + }) + + // Tarihe göre sırala, en güncel ilk 3 aktiviteyi al + const latestActivities = recentActivities + .sort((a, b) => b.date.getTime() - a.date.getTime()) + .slice(0, 3) return (
-

{translate('::App.Forum.Dashboard.Statistics')}

- +

+ {translate('::App.Forum.Dashboard.Statistics')} +

+
{stats.map((stat, index) => { - const Icon = stat.icon; + const Icon = stat.icon return (
-
+
@@ -70,38 +121,30 @@ export function AdminStats({ categories, topics, posts }: AdminStatsProps) {

{stat.subtitle}

- ); + ) })}
{/* Recent Activity */}
-

{translate('::App.Forum.Dashboard.RecentActivity')}

+

+ {translate('::App.Forum.Dashboard.RecentActivity')} +

-
-
-
-

{translate('::App.Forum.Dashboard.GeneralDiscussion')}

-

2 hours ago

+ {latestActivities.map((activity, index) => ( +
+
+
+

{activity.message}

+

+ {formatDistanceToNow(activity.date, { addSuffix: true })} +

+
-
-
-
-
-

{translate('::App.Forum.Dashboard.Postmarked')}

-

4 hours ago

-
-
-
-
-
-

{translate('::App.Forum.Dashboard.FeatureRequests')}

-

1 day ago

-
-
+ ))}
- ); -} \ No newline at end of file + ) +}