UNPKG

@defikitdotnet/x-ai-combat

Version:

XCombatAI - Social Media Engagement Template for the Agent Framework

76 lines 3.45 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { useState } from 'react'; import { useAuth } from '../contexts/AuthContext'; const StatisticsPanel = () => { const [statistics, setStatistics] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const { user } = useAuth(); console.log("🚀 ~ user:", user); // useEffect(() => { // const fetchStatistics = async () => { // if (!user) { // setLoading(false); // return; // } // try { // const backendUrl = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:3005'; // setLoading(true); // const response = await fetch(`${backendUrl}/xaicombat/api/interactions/my-stats`, { // credentials: 'include' // Include cookies for JWT authentication // }); // if (!response.ok) { // throw new Error('Failed to fetch statistics'); // } // const data = await response.json(); // setStatistics(data.data); // } catch (err) { // setError((err as Error).message); // console.error('Error fetching statistics:', err); // } finally { // setLoading(false); // } // }; // // fetchStatistics(); // }, [user]); if (loading) { return _jsx("div", { className: "flex justify-center py-4", children: "Loading statistics..." }); } if (error) { return _jsxs("div", { className: "text-red-500 dark:text-red-400 py-2", children: ["Error: ", error] }); } if (!statistics || !user) { return _jsx("div", { className: "text-gray-500 dark:text-gray-400 py-2", children: "No statistics available." }); } // Định nghĩa mảng các thống kê để hiển thị theo thứ tự const statsItems = [ { label: "Fame Points", value: statistics.famePoints, icon: "⭐" }, { label: "Likes", value: statistics.likes, icon: "❤️" }, { label: "Replies", value: statistics.replies, icon: "↩️" }, { label: "Retweets", value: statistics.retweets, icon: "🔄" }, { label: "Quotes", value: statistics.quotes, icon: "💬" } ]; return (_jsx("div", { className: "w-full flex flex-wrap justify-center sm:justify-between", children: statsItems.map((item, index) => (_jsxs("div", { className: "flex flex-col items-center justify-center w-[45%] sm:w-[19%] mb-4 sm:mb-0 mx-1 bg-brand-50 dark:bg-brand-900/30 rounded-lg p-4 shadow-sm", children: [_jsxs("div", { className: "flex items-center mb-2", children: [_jsx("span", { className: "mr-1 text-lg", role: "img", "aria-label": item.label, children: item.icon }), _jsx("span", { className: "text-brand-500 dark:text-brand-400 text-2xl sm:text-3xl font-bold", children: item.value })] }), _jsx("div", { className: "text-brand-700 dark:text-brand-300 text-xs sm:text-sm font-medium text-center", children: item.label })] }, index))) })); }; export default StatisticsPanel; //# sourceMappingURL=StatisticsPanel.js.map