From caa9ecca639e9c6a68eccb1620bec152f88d879b Mon Sep 17 00:00:00 2001 From: MythEclipse Date: Wed, 3 Jun 2026 18:17:25 +0700 Subject: [PATCH] feat(analytics): add AI stats, attachment stats, and moderation actions queries to useAnalytics hook --- .../analytics/components/ActivityChart.tsx | 12 +++- .../features/analytics/hooks/useAnalytics.ts | 69 ++++++++++++++----- 2 files changed, 61 insertions(+), 20 deletions(-) diff --git a/services/frontend/src/features/analytics/components/ActivityChart.tsx b/services/frontend/src/features/analytics/components/ActivityChart.tsx index 4de4e95..258b372 100644 --- a/services/frontend/src/features/analytics/components/ActivityChart.tsx +++ b/services/frontend/src/features/analytics/components/ActivityChart.tsx @@ -27,7 +27,7 @@ export function ActivityChart({ hourly, loading }: ActivityChartProps) { return { hour: `${String(jakartaHour).padStart(2, "0")}:00`, clean: b.clean, - warned: 0, + warned: b.warned, flagged: b.flagged, error: b.error, total: b.count, @@ -46,8 +46,9 @@ export function ActivityChart({ hourly, loading }: ActivityChartProps) {
-
+
Clean + Warned Flagged Error
@@ -55,6 +56,7 @@ export function ActivityChart({ hourly, loading }: ActivityChartProps) { {data.map((bucket) => { const total = Math.max(bucket.total, 1); const clean = bucket.clean / total; + const warned = bucket.warned / total; const flagged = bucket.flagged / total; const error = bucket.error / total; return ( @@ -70,9 +72,13 @@ export function ActivityChart({ hourly, loading }: ActivityChartProps) {
+
fetchAIStats({ guildId, channelId, hours }), + enabled: !!guildId, + staleTime: 30_000, + placeholderData: keepPreviousData, + }); + + const attachmentStatsQuery = useQuery({ + queryKey: keys.attachmentStats, + queryFn: () => fetchAttachmentStats({ guildId, channelId, hours }), + enabled: !!guildId, + staleTime: 30_000, + placeholderData: keepPreviousData, + }); + + const moderationActionsQuery = useQuery({ + queryKey: keys.moderationActions, + queryFn: () => fetchModerationActions({ guildId, channelId, hours, limit: 50 }), + enabled: !!guildId, + staleTime: 30_000, + placeholderData: keepPreviousData, + }); + const refresh = useCallback(() => { if (!guildId) return; window.dispatchEvent(new CustomEvent("analytics_refresh")); @@ -94,7 +116,6 @@ export function useAnalytics({ useEffect(() => { const handler = () => { if (!guildId) return; - // Use queryClient.invalidateQueries from the React Query internals window.dispatchEvent(new CustomEvent("analytics_force_refresh")); }; window.addEventListener("analytics_refresh", handler); @@ -128,6 +149,17 @@ export function useAnalytics({ heatmapLoading: heatmapQuery.isLoading && !heatmapQuery.data, heatmapFetching: heatmapQuery.isFetching && !heatmapQuery.isLoading, + aiStats: aiStatsQuery.data ?? null, + aiStatsLoading: aiStatsQuery.isLoading && !aiStatsQuery.data, + + attachmentStats: attachmentStatsQuery.data ?? null, + attachmentStatsLoading: + attachmentStatsQuery.isLoading && !attachmentStatsQuery.data, + + moderationActions: moderationActionsQuery.data ?? [], + moderationActionsLoading: + moderationActionsQuery.isLoading && !moderationActionsQuery.data, + hourly: overview?.hourly ?? ([] as HourlyBucket[]), topics: overview?.topics ?? ([] as TopicTrend[]), topUsers: overview?.top_users ?? ([] as UserStat[]), @@ -139,9 +171,12 @@ export function useAnalytics({ } export type { + AIStats, AnalyticsOverview, + AttachmentStats, HeatmapCell, HourlyBucket, + ModerationActionRecord, TopicTrend, TrendBucket, UserStat,