@defikitdotnet/x-ai-combat
Version:
XCombatAI - Social Media Engagement Template for the Agent Framework
78 lines • 3.74 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const AuthContext_1 = require("../contexts/AuthContext");
const StatisticsPanel = () => {
const [statistics, setStatistics] = (0, react_1.useState)(null);
const [loading, setLoading] = (0, react_1.useState)(true);
const [error, setError] = (0, react_1.useState)(null);
const { user } = (0, AuthContext_1.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 (0, jsx_runtime_1.jsx)("div", { className: "flex justify-center py-4", children: "Loading statistics..." });
}
if (error) {
return (0, jsx_runtime_1.jsxs)("div", { className: "text-red-500 dark:text-red-400 py-2", children: ["Error: ", error] });
}
if (!statistics || !user) {
return (0, jsx_runtime_1.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 ((0, jsx_runtime_1.jsx)("div", { className: "w-full flex flex-wrap justify-center sm:justify-between", children: statsItems.map((item, index) => ((0, jsx_runtime_1.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: [(0, jsx_runtime_1.jsxs)("div", { className: "flex items-center mb-2", children: [(0, jsx_runtime_1.jsx)("span", { className: "mr-1 text-lg", role: "img", "aria-label": item.label, children: item.icon }), (0, jsx_runtime_1.jsx)("span", { className: "text-brand-500 dark:text-brand-400 text-2xl sm:text-3xl font-bold", children: item.value })] }), (0, jsx_runtime_1.jsx)("div", { className: "text-brand-700 dark:text-brand-300 text-xs sm:text-sm font-medium text-center", children: item.label })] }, index))) }));
};
exports.default = StatisticsPanel;
//# sourceMappingURL=StatisticsPanel.js.map