-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
121 lines (111 loc) · 4.99 KB
/
Copy pathApp.js
File metadata and controls
121 lines (111 loc) · 4.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import React, { useState, useEffect } from 'react';
import { motion } from 'framer-motion';
import Login from './components/Login';
import Dashboard from './components/Dashboard';
import Logs from './components/Logs';
import CommandInput from './components/CommandInput';
import { mockUser } from './mock/botData';
import { apiGetStats } from './utils/api';
function App() {
const [isLoggedIn, setIsLoggedIn] = useState(false);
const [user, setUser] = useState(null);
const [botStatus, setBotStatus] = useState(false);
const [stats, setStats] = useState({ users: 0, servers: 0 });
const [loading, setLoading] = useState(true);
useEffect(() => {
// Verifica si ya está logueado (backend maneja sesión via cookies)
const checkAuth = async () => {
const BACKEND_URL = process.env.REACT_APP_BACKEND_URL || 'http://localhost:5000';
if (BACKEND_URL !== 'http://localhost:5000') {
try {
const response = await fetch(`${BACKEND_URL}/auth/check`, {
credentials: 'include'
});
if (response.ok) {
const userData = await response.json();
if (userData.id === 'TU_DISCORD_ID_AQUI') {
setUser(userData);
setIsLoggedIn(true);
}
}
} catch (error) {
console.log('No auth inicial');
}
}
setLoading(false);
};
checkAuth();
// Carga stats iniciales
const loadStats = async () => {
const data = await apiGetStats();
setStats(data || { users: 42, servers: 5 }); // Fallback
setBotStatus(data.botStatus || false);
};
loadStats();
}, []);
const handleLogin = (loggedUser) => {
setUser(loggedUser);
setIsLoggedIn(true);
};
const handleToggleBot = async () => {
// Llama a API real
const result = await apiToggleBot(!botStatus);
if (result.success) {
setBotStatus(!botStatus);
// Actualiza stats del backend (ajusta según respuesta)
const newStats = await apiGetStats();
setStats(newStats);
} else {
alert(`¡Ups! ${result.message || 'Error al togglear bot – ¿Backend vivo?'}`);
}
};
const handleSendCommand = (cmd) => {
console.log('✅ Comando enviado y procesado:', cmd);
// Backend ya lo ejecuta y emite log via socket
};
if (loading) {
return (
<div className="min-h-screen flex items-center justify-center bg-gray-900">
<motion.div
className="text-white text-xl flex items-center gap-3"
animate={{ rotate: 360 }}
transition={{ duration: 1, repeat: Infinity, ease: 'linear' }}
>
Cargando Panel...
<div className="w-6 h-6 border-2 border-blue-500 border-t-transparent rounded-full" />
</motion.div>
</div>
);
}
if (!isLoggedIn) {
return <Login onLogin={handleLogin} />;
}
return (
<div className="min-h-screen bg-gradient-to-br from-gray-900 via-black to-gray-900">
<div className="container mx-auto px-4 py-8 max-w-6xl">
<motion.header
className="flex justify-between items-center mb-8 bg-gray-800/30 backdrop-blur-xl rounded-2xl p-4 border border-gray-700"
initial={{ opacity: 0, y: -20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ duration: 0.5 }}
>
<h1 className="text-4xl font-bold bg-gradient-to-r from-indigo-400 via-purple-400 to-blue-400 bg-clip-text text-transparent">
BotPanel Pro
</h1>
<div className="flex items-center gap-3 bg-gray-700/50 px-4 py-2 rounded-xl border border-indigo-500/50">
<img src={user.avatar} alt={user.username} className="w-10 h-10 rounded-full border-2 border-indigo-500" />
<span className="font-semibold text-white">{user.username}</span>
</div>
</motion.header>
<main className="space-y-8">
<Dashboard botStatus={botStatus} onToggleBot={handleToggleBot} stats={stats} />
<div className="grid grid-cols-1 lg:grid-cols-2 gap-8">
<Logs />
<CommandInput onSendCommand={handleSendCommand} />
</div>
</main>
</div>
</div>
);
}
export default App;