+
)
} else {
return (
-
+
)
}
}
diff --git a/frontend/src/context/chess-game-context.jsx b/frontend/src/context/chess-game-context.jsx
index 399ec0b..6949588 100644
--- a/frontend/src/context/chess-game-context.jsx
+++ b/frontend/src/context/chess-game-context.jsx
@@ -1,9 +1,9 @@
import React, { createContext, useReducer, useRef, useState } from 'react'
-import { ChessModified, chessInit } from '../../utils/chess';
+import { ChessModified, chessInit } from '../utils/chess';
import { DISPATCH_EVENTS, SOCKET_EVENTS } from '../constants';
import { socket } from '../socket';
const { CAPTURE_PIECE, MOVE_PIECE, SELECT_PIECE, JUMP_TO, SET_GAME_HISTORY, END_GAME } = DISPATCH_EVENTS
-const { GAME_END, CHESS_MOVE, CHESS_OPPONENT_MOVE } = SOCKET_EVENTS;
+const { GAME_END, CHESS_MOVE } = SOCKET_EVENTS;
export const ChessGameContext = createContext();
// myColor: null, chess: null, chessBoard: null, moveHints: null, selected: null, dispatch: null, handleOpponentMove: null, handleSquareClick: null, getSquareColor: null, isSquareMarked: null, selectPiece: null, handleDrop: null
@@ -171,7 +171,7 @@ const ChessGameContextProvider = ({ children }) => {
}
}
- function selectPiece({ square, type, color: pieceColor }) {
+ function selectPiece({ square, color: pieceColor }) {
if (pieceColor === myColor && myColor === chess.turn()) {
dispatch({ type: SELECT_PIECE, val: square });
}
diff --git a/frontend/src/context/user-data-context.jsx b/frontend/src/context/user-data-context.jsx
index 0e3b28d..fa0db57 100644
--- a/frontend/src/context/user-data-context.jsx
+++ b/frontend/src/context/user-data-context.jsx
@@ -1,14 +1,12 @@
import React, { createContext, useEffect, useState } from 'react'
-import Cookie from 'js-cookie'
-export const UserDataContext = createContext();
+export const UserDataContext = createContext();
const UserDataContextProvider = ({ children }) => {
// TODO: use more secure mechanism insted of localstorage
const [isLoggedIn, setIsLoggedIn] = useState(JSON.parse(localStorage.getItem('loggedIn')));
const [user, setUser] = useState(null);
const [errorMessage, setErrorMessage] = useState("");
- console.log(user)
async function fetchUserDetails() {
try {
@@ -22,8 +20,7 @@ const UserDataContextProvider = ({ children }) => {
if (response.ok) {
setUser(resData);
} else {
- console.log(resData.devMessage);
- setErrorMessage(resData.userMessage);
+ setErrorMessage(resData.message);
}
}
} catch (err) {
@@ -36,7 +33,7 @@ const UserDataContextProvider = ({ children }) => {
}, []);
return (
-
+
{children}
)
diff --git a/frontend/src/hooks/useCountDown.jsx b/frontend/src/hooks/useCountDown.jsx
index bb1c3d8..7d69aa3 100644
--- a/frontend/src/hooks/useCountDown.jsx
+++ b/frontend/src/hooks/useCountDown.jsx
@@ -1,10 +1,10 @@
-import React, { useEffect, useState } from 'react'
+import { useEffect, useState } from 'react'
-const useCountDown = (timeLimit,isTimerOn) => {
+const useCountDown = (timeLimit, isTimerOn) => {
const [timeLeft, setTimeLeft] = useState(timeLimit * 60 * 1000);
useEffect(() => {
- if(!isTimerOn) {
+ if (!isTimerOn) {
return;
}
if (timeLeft > 0) {
diff --git a/frontend/src/pages/Authentication/Authentication.jsx b/frontend/src/pages/Authentication/Authentication.jsx
index f2669c5..8330431 100644
--- a/frontend/src/pages/Authentication/Authentication.jsx
+++ b/frontend/src/pages/Authentication/Authentication.jsx
@@ -73,7 +73,7 @@ const LoginForm = () => {
setIsLoggedIn(true);
return navigate('/');
} else {
- setErrorMsg(resData.userMessage || "Something went wrong");
+ setErrorMsg(resData.message || "Something went wrong");
}
} catch (err) {
setIsLoading(false);
@@ -123,8 +123,8 @@ const SignupForm = () => {
} else {
setIsLoading(false);
console.log(resData);
- console.log(resData.devMessage);
- setErrorMsg(resData.userMessage);
+ console.log(resData.description);
+ setErrorMsg(resData.message);
resData?.error?.username && setError('username', { message: resData.error.username });
resData?.error?.email && setError('email', { message: resData.error.email });
}
diff --git a/frontend/src/pages/Chess/ChessGame.jsx b/frontend/src/pages/Chess/ChessGame.jsx
index f2f15db..53f495c 100644
--- a/frontend/src/pages/Chess/ChessGame.jsx
+++ b/frontend/src/pages/Chess/ChessGame.jsx
@@ -1,18 +1,18 @@
import { Avatar, Button, Flex, Group, Image, Loader, MediaQuery, Modal, NavLink, Text, Title } from '@mantine/core'
import React, { useContext, useEffect, useState } from 'react'
import ChessBoard from '../Chess/ChessBoard'
-import { useNavigate, useParams } from 'react-router-dom'
+import { useNavigate } from 'react-router-dom'
import { socket } from '../../socket'
-import { getUserData } from '../../../utils/auth'
+import { getUserData } from '../../utils/auth'
import { ChessGameContext } from '../../context/chess-game-context'
import GameHistory from '../../components/GameHistory'
-import Timer from './Timer'
+import MainLoader from '../../components/MainLoader'
import { useDisclosure } from '@mantine/hooks'
import { SOCKET_EVENTS } from '../../constants'
-const { CONNECT, DISCONNECT, CHESS_OPPONENT_MOVE, USER_RESIGNED, CONNECTION, JOIN_ROOM, JOIN_ROOM_ERROR, JOIN_ROOM_SUCCESS, ROOM_FULL, USER_JOINED_ROOM } = SOCKET_EVENTS;
+const { CONNECT, DISCONNECT, CHESS_OPPONENT_MOVE, USER_RESIGNED, JOIN_ROOM, JOIN_ROOM_ERROR, JOIN_ROOM_SUCCESS, ROOM_FULL, USER_JOINED_ROOM } = SOCKET_EVENTS;
const ChessGame = () => {
- const { setGameHistory, isTimerOn, setIsTimerOn, hasGameEnded, gameEndedReason, endGame } = useContext(ChessGameContext);
+ const { setGameHistory, hasGameEnded, gameEndedReason, endGame } = useContext(ChessGameContext);
const [gameEndedModalOpen, modalFunctions] = useDisclosure(true);
const user = getUserData();
@@ -67,7 +67,7 @@ const ChessGame = () => {
console.log('Socket disconnected due to', reason);
});
- socket.on(CHESS_OPPONENT_MOVE, (data) => {
+ socket.on(CHESS_OPPONENT_MOVE, () => {
// console.log(data);
// setIsTimerOn(true);
})
@@ -76,9 +76,9 @@ const ChessGame = () => {
setIsWaiting(false);
});
- socket.on(USER_RESIGNED, (roomID, username) => {
+ socket.on(USER_RESIGNED, () => {
endGame('RESIGN');
- })
+ });
return () => {
socket.offAny();
@@ -87,7 +87,7 @@ const ChessGame = () => {
}, []);
if (!hasJoinedRoom) return (
-
+
)
return (
@@ -104,7 +104,9 @@ const ChessGame = () => {
style={{ width: "500px" }}
p="2px"
label={isWaiting ? "Waiting for opponent..." : opponent}
- icon={}
+ icon={
+ {opponent[0].toUpperCase}
+ }
description={"description"}
/>
{/* */}
@@ -128,7 +130,9 @@ const ChessGame = () => {
style={{ width: "500px" }}
p="2px"
label={username}
- icon={}
+ icon={
+ {username[0].toUpperCase()}
+ }
description={"description"}
/>
{/* */}
@@ -140,7 +144,7 @@ const ChessGame = () => {
height: '100%',
textAlign: 'center',
borderRadius: '10px',
- backgroundColor:'#272623'
+ backgroundColor: '#272623'
}} bg='gray' justify='start' py='md' align='center' direction='column' h="600px">
Game Data
diff --git a/frontend/src/pages/Chess/Timer.jsx b/frontend/src/pages/Chess/Timer.jsx
index 69f45b6..64a0fcf 100644
--- a/frontend/src/pages/Chess/Timer.jsx
+++ b/frontend/src/pages/Chess/Timer.jsx
@@ -4,7 +4,7 @@ import { Box } from '@mantine/core';
import { ChessGameContext } from '../../context/chess-game-context';
const Timer = ({ on }) => {
- const { isTimerOn } = useContext(ChessGameContext)
+ // const { isTimerOn } = useContext(ChessGameContext)
const timeLimit = localStorage.getItem('timeLimit');
const [seconds, minutes] = useCountDown(timeLimit, on);
return (
diff --git a/frontend/src/pages/Play/ChallengeFriend.jsx b/frontend/src/pages/Play/ChallengeFriend.jsx
index 03ae9e2..c8854a8 100644
--- a/frontend/src/pages/Play/ChallengeFriend.jsx
+++ b/frontend/src/pages/Play/ChallengeFriend.jsx
@@ -1,7 +1,7 @@
-import { Avatar, Button, Card, Flex, Image, Select, Text, TextInput, Title } from '@mantine/core'
+import { Avatar, Button, Card, Flex, Select, Text, Title } from '@mantine/core'
import React from 'react'
import { Form, redirect, useParams } from 'react-router-dom'
-import { getAuthToken, getUserData } from '../../../utils/auth'
+import { getUserData } from '../../utils/auth'
const ChallengeFriend = () => {
const params = useParams();
@@ -9,12 +9,12 @@ const ChallengeFriend = () => {
return (