@@ -508,7 +529,7 @@ You can return the answer in any order.`,
{problem.description}
- {problem.examples.map((example, index) => (
+ {problem.examples?.map((example, index) => (
Example {index + 1}:
@@ -524,15 +545,16 @@ You can return the answer in any order.`,
Constraints:
-
- {problem.constraints.map((constraint, index) => (
- - • {constraint}
- ))}
-
+
+ {problem.constraints?.map((constraint, index) => (
+ - {constraint}
+ ))}
+
+
-
);
+};
/**
* Render code editor panel
@@ -599,31 +621,33 @@ You can return the answer in any order.`,
/>
- {/* Test Results */}
- {testResults.length > 0 && (
-
-
Test Results:
-
- {testResults.map((result) => (
-
- {result.passed ? (
-
- ) : (
-
- )}
-
- Test {result.id}: {result.input}
-
- {!result.passed && (
-
- Expected {result.expected}, got {result.actual}
-
- )}
-
- ))}
-
+{/* Test Results */}
+{testResults.length > 0 && (
+
+
Test Results:
+
+ {testResults.map(r => (
+
+ {r.passed ? (
+
+ ) : (
+
+ )}
+ {/* Aquí mostramos la línea completa del servidor */}
+ {r.text}
- )}
+ ))}
+
+ {/* Resumen igual al estilo que prefieres */}
+
+ Result: {testResults.filter(r => r.passed).length}/{testResults.length} tests passed.{" "}
+ {testResults.every(r => r.passed)
+ ? All passed 🎉
+ : Some failed ✗}
+
+
+)}
+
);
diff --git a/client/src/pages/Login.jsx b/client/src/pages/Login.jsx
index 9591c4e..a06bffc 100644
--- a/client/src/pages/Login.jsx
+++ b/client/src/pages/Login.jsx
@@ -10,13 +10,17 @@ const Login = ({ navigate, onLogin }) => {
// here we are going to send the unique googleId to the backend to find or create a user
try {
+ console.log('The name is this:', user.name);
console.log("THE USER ID IS THIS:", user.googleId);
const response = await fetch('/api/user/auth/google', {
method: 'Post',
headers: {
'Content-Type': 'application/json'
},
- body: JSON.stringify({ googleId: user.googleId })
+ body: JSON.stringify({
+ googleId: user.googleId,
+ name: user.username
+ })
});
const dbUser = await response.json();
@@ -27,8 +31,6 @@ const Login = ({ navigate, onLogin }) => {
console.error('Error logging in with Google:', error);
}
- // Call the parent's onLogin function which handles navigation
- onLogin(user);
// Don't navigate here - let App.jsx handle it via onLogin
};
diff --git a/client/src/pages/MatchLobby.jsx b/client/src/pages/MatchLobby.jsx
index e903462..8be9fe1 100644
--- a/client/src/pages/MatchLobby.jsx
+++ b/client/src/pages/MatchLobby.jsx
@@ -25,6 +25,10 @@ const MatchLobby = ({ navigate, user, mode = 'quick' }) => {
const [success, setSuccess] = useState('');
const [connectionStatus, setConnectionStatus] = useState('disconnected');
const [playersInQueue, setPlayersInQueue] = useState(0);
+
+ const [language, setLanguage] = useState('python'); // python by defect
+ const [category, setCategory] = useState(''); // empty means any
+ const topics = ['arrays','linked list','graphs','trees'];
// Available difficulty levels for problems
const difficulties = [
@@ -93,12 +97,7 @@ const MatchLobby = ({ navigate, user, mode = 'quick' }) => {
const handleMatchFound = (data) => {
console.log('Match found:', data);
setIsSearching(false);
- setSuccess('Match found! Starting game...');
-
- // Navigate to game room after brief success message
- setTimeout(() => {
- navigate('game-room', { matchData: data });
- }, 1500);
+ setSuccess('Match found! Waiting for both players…');
};
const handleMatchCancelled = (data) => {
@@ -122,14 +121,18 @@ const MatchLobby = ({ navigate, user, mode = 'quick' }) => {
const handleRoomJoined = (data) => {
console.log('Room joined:', data);
+ setRoomCode(data.roomCode);
setSuccess('Room joined! Waiting for opponent...');
- // If room has 2 players, start the game
- if (data.playerCount >= 2) {
- setTimeout(() => {
- navigate('game-room', { roomData: data });
- }, 1000);
- }
+ };
+
+ const handleStartGame = ({ roomCode: rc, problem, timeLimit }) => {
+ console.log('🔥 [MatchLobby] start_game received:', { rc, problem, timeLimit });
+ navigate('game-room', {
+ roomCode: rc,
+ problem,
+ timeLimit: timeLimit || 600
+ });
};
const handleRoomError = (data) => {
@@ -137,10 +140,6 @@ const MatchLobby = ({ navigate, user, mode = 'quick' }) => {
setError(data.message || 'Room error occurred.');
};
- const handleGameStarted = (data) => {
- console.log('Game started:', data);
- navigate('game-room', { gameData: data });
- };
const handleError = (data) => {
console.error('Socket error:', data);
@@ -154,8 +153,9 @@ const MatchLobby = ({ navigate, user, mode = 'quick' }) => {
gameSocket.on('queue_update', handleQueueUpdate);
gameSocket.on('room_created', handleRoomCreated);
gameSocket.on('room_joined', handleRoomJoined);
+ gameSocket.on('start_game', handleStartGame);
gameSocket.on('room_error', handleRoomError);
- gameSocket.on('game_started', handleGameStarted);
+ //gameSocket.on('game_started', handleGameStarted);
gameSocket.on('error', handleError);
// Cleanup function - removes event listeners when component unmounts
@@ -168,8 +168,9 @@ const MatchLobby = ({ navigate, user, mode = 'quick' }) => {
gameSocket.off('queue_update', handleQueueUpdate);
gameSocket.off('room_created', handleRoomCreated);
gameSocket.off('room_joined', handleRoomJoined);
+ gameSocket.off('start_game', handleStartGame);
gameSocket.off('room_error', handleRoomError);
- gameSocket.off('game_started', handleGameStarted);
+ //gameSocket.off('game_started', handleGameStarted);
gameSocket.off('error', handleError);
// Leave any active matchmaking when component unmounts
@@ -200,23 +201,23 @@ const MatchLobby = ({ navigate, user, mode = 'quick' }) => {
* Create a private room with selected difficulty
*/
const generateRoomCode = () => {
- // Check connection before attempting to create room
- if (!gameSocket.isSocketConnected()) {
- setError('Please wait for connection to establish.');
- return;
- }
-
- console.log('Creating room with difficulty:', difficulty);
-
- // Use GameSocket class method to create room
- gameSocket.createRoom({
- difficulty: difficulty,
- creator: {
- id: user?.id,
- username: user?.username
+ if (!gameSocket.isSocketConnected()) {
+ setError('Please wait for connection to establish.');
+ return;
}
- });
- };
+
+ console.log('Creating room with:', { difficulty, language, category });
+
+ gameSocket.createRoom({
+ difficulty,
+ language,
+ category,
+ creator: {
+ id: user.id,
+ username: user.username
+ }
+ });
+ };
/**
* Copy room code to clipboard for sharing
@@ -434,6 +435,37 @@ const MatchLobby = ({ navigate, user, mode = 'quick' }) => {
+ {/* Topic Selection */}
+