Skip to content

Commit

Permalink
Core: Removed all console.log
Browse files Browse the repository at this point in the history
  • Loading branch information
hanmpark committed Nov 14, 2024
1 parent 93c845e commit a4a1a8f
Show file tree
Hide file tree
Showing 16 changed files with 9 additions and 63 deletions.
2 changes: 0 additions & 2 deletions frontend/src/api/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export const formatUserData = user => {

export const getUser = async () => {
try {
console.log('Getting current user...');
const res = await API.get(`users/@me/profile`);
const user = formatUserData(res.data);
return user;
Expand All @@ -28,7 +27,6 @@ export const getUser = async () => {

export const getUserById = async (id) => {
try {
console.log('Getting user by username...');
const res = await API.get(`users/${id}/profile`);

const user = formatUserData(res.data);
Expand Down
4 changes: 0 additions & 4 deletions frontend/src/components/Chat/tools/DisplayChatMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const DisplayChatMessages = ({ realConvo, userID, messagesEndRef, otherUser }) =
navigate(`/tournaments/${tournamentID}`);
registerForTournament(tournamentID);
} catch (error) {
console.log(error);
addNotification('error', error?.response?.data?.error || t('chat.invite.errorAccept'));
}
}
Expand All @@ -48,7 +47,6 @@ const DisplayChatMessages = ({ realConvo, userID, messagesEndRef, otherUser }) =
addNotification('success', t('chat.invite.inviteAccepted'));
navigate('/game-challenge?inviteID=' + inviteID);
} catch (error) {
console.log(error);
addNotification('error', error?.response?.data?.error || t('chat.invite.errorAccept'));
}
}
Expand All @@ -58,7 +56,6 @@ const DisplayChatMessages = ({ realConvo, userID, messagesEndRef, otherUser }) =
await API.post(`/users/${challengerID}/challenge/${inviteID}/deny`);
addNotification('success', t('chat.invite.inviteDeclined'));
} catch (error) {
console.log(error);
addNotification('error', error?.response?.data?.error || t('chat.invite.errorDecline'));
}
}
Expand All @@ -71,7 +68,6 @@ const DisplayChatMessages = ({ realConvo, userID, messagesEndRef, otherUser }) =
);
} else {
let previousSenderID = null;
console.log(realConvo);

return (
<ChatBubbleContainer>
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/components/Game/Tournament/CreateTournament.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ const CreateTournament = ({ setOptions }) => {
isPublic,
maxParticipants
});
console.log('CreateTournament: tournament created');
console.log('CreateTournament:', user.tournamentID);
registerForTournament(response.data.tournamentID);
navigate(`/tournaments/${response.data.tournamentID}`);
} catch (error) {
Expand Down
9 changes: 0 additions & 9 deletions frontend/src/components/Game/Tournament/GameTournament.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,9 @@ const GameTournament = () => {

const { sendMessage, lastMessage, readyState } = useWebSocket(socketUrl, {
onOpen: () => {
console.log("Match WebSocket connection opened");
reconnectAttempts.current = 0;
},
onClose: (event) => {
console.log("Match WebSocket connection closed");
if (event.code === 1006 && !gameOver) handleReconnect();
},
shouldReconnect: () => !gameOver,
Expand All @@ -64,9 +62,7 @@ const GameTournament = () => {
const handleReconnect = useCallback(() => {
if (reconnectAttempts.current < maxReconnectAttempts) {
reconnectAttempts.current += 1;
console.log(`Attempting to reconnect... (Attempt ${reconnectAttempts.current})`);
} else {
console.log('Max reconnection attempts reached. Redirecting to home.');
navigate('/');
}
}, [navigate]);
Expand All @@ -80,8 +76,6 @@ const GameTournament = () => {
if (!resetMatch) return;
const matchUrl = process.env.REACT_APP_ENV === 'production' ? '/ws/match' : 'ws://localhost:8000/ws/match';

console.log('GameTournament.js: resetMatch', resetMatch);

setSocketUrl(`${matchUrl}?t=${Date.now()}`);
currentMatchId.current = resetMatch.matchID;

Expand Down Expand Up @@ -109,7 +103,6 @@ const GameTournament = () => {
playerId.current = playerA.userID;
setKey(prevKey => prevKey + 1);
setResetMatch(null);
console.log('GameTournament.js: match resseted');
}, [resetMatch, setResetMatch]);


Expand Down Expand Up @@ -210,8 +203,6 @@ const GameTournament = () => {
const handler = handlers[data.e];
if (handler) {
handler();
} else {
console.log('GameTournament.js: Unhandled message:', data);
}
}, [lastMessage, sendMessage]);

Expand Down
4 changes: 1 addition & 3 deletions frontend/src/components/Game/Tournament/JoinTournament.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ const JoinTournament = () => {
const fetchTournament = async () => {
try {
const response = await API.get(`/tournaments/${tournamentID}`);
console.log('JoinTournament.js: fetchTournament', response.data);
updateTournament(response.data);
} catch (error) {
addNotification('error', error.response?.data?.error || 'Error fetching tournament data');
Expand Down Expand Up @@ -84,8 +83,7 @@ const JoinTournament = () => {

const handleLeave = async () => {
try {
const response = await API.delete(`/tournaments/@me`);
console.log('JoinTournament.js: handleLeave', response.data);
await API.delete(`/tournaments/@me`);
} catch (error) {
addNotification('error', error.response?.data?.error || 'Error leaving tournament');
}
Expand Down
4 changes: 1 addition & 3 deletions frontend/src/components/Game/remote/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ const Game = () => {
const handleReconnect = useCallback(() => {
if (reconnectAttempts.current < maxReconnectAttempts) {
reconnectAttempts.current += 1;
console.log(`Attempting to reconnect... (Attempt ${reconnectAttempts.current})`);
} else {
console.log('Max reconnection attempts reached. Redirecting to home.');
navigate('/');
}
}, [navigate]);
Expand Down Expand Up @@ -152,7 +150,7 @@ const Game = () => {
case 'PADDLE_RATE_LIMIT': // ignoring
break;
default:
console.log('Unhandled message:', data);
break;
}
}
}, [lastMessage, gameState.player?.userID, handleHeartbeatAck, navigate]);
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/components/Game/remote/Rewards.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ const Rewards = ({ endGameData, isSpectator = false, isTournament }) => {
const { user } = useAuth();
const { t } = useTranslation();

console.log('Rewards.js:', endGameData);

return (
<OverlayContainer>
<h1>{t('game.gameOver')}</h1>
Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/Navigation/ProfileDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const ProfileDropdown = () => {
try {
if (user.tournamentID) {
await API.delete(`/tournaments/@me`);
console.log('ProfileDropdown.js: successfully left tournament');
}
setIsLoggedIn(false);
setUser(null);
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/components/Root/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ const Root = () => {

useEffect(() => {
if (!user?.tournamentID) return;
console.log('index.js:', user.tournamentID);

const leaveTournament = async () => {
try {
Expand All @@ -53,7 +52,6 @@ const Root = () => {
};
if (!location.pathname.includes(`/tournaments/${user.tournamentID}`)) {
leaveTournament();
console.log('index.js: leaving tournament');
}
}, [location, user?.tournamentID, addNotification, setUser]);

Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/Settings/Privacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ const Privacy = () => {
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(blobUrl);
console.log('Data harvested');
setIsHarvesting(true);
addNotification('success', t('settings.privacy.downloadingMessage'));
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ErrorMessage from '../../../../styles/shared/ErrorMessage.styled';
import { useNotification } from '../../../../context/NotificationContext';
import { useTranslation } from 'react-i18next';

const TwoFactorAuthSecurity = ({ formData, setUser, setShowTwoFactorAuth }) => {
const TwoFactorAuthSecurity = ({ formData, setUser, setShowTwoFactorAuth, setMainError }) => {
const { addNotification } = useNotification();
const [availablePlatforms, setAvailablePlatforms] = useState([]);
const [authCode, setAuthCode] = useState('');
Expand Down Expand Up @@ -44,17 +44,16 @@ const TwoFactorAuthSecurity = ({ formData, setUser, setShowTwoFactorAuth }) => {

const submissionData = { ...formData };

console.log('TwofactorAuthSecurity submissionData before:', submissionData);
['password', 'phone_number', 'email'].forEach(field => {
if (!submissionData[field]) {
delete submissionData[field];
}
});
console.log('TwofactorAuthSecurity submissionData after:', submissionData);

API.patch('users/@me/profile', { ...submissionData, otp: authCode })
.then(() => {
addNotification('success', t('settings.security.successMessage'));
setMainError('');
getUser()
.then(res => {
setUser(res);
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/Settings/Security/Security.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ const Security = ({ user, setUser }) => {
formData={formData}
setUser={setUser}
setShowTwoFactorAuth={setShowTwoFactorAuth}
setMainError={setError}
/>
)}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ const TwoFactorAuthSecurity = ({ formData, setUser, setSuccess, setShowTwoFactor

const handlePlatform = (platform) => {
API.post('auth/totp/request', { platform })
.then(() => {
console.log('2FA: Request sent');
})
.catch(err => {
console.log('2FA: Request failed');
setError(err.response.data.error);
});
};
Expand All @@ -49,13 +45,11 @@ const TwoFactorAuthSecurity = ({ formData, setUser, setSuccess, setShowTwoFactor

setDisableVerify(true);
API.patch('users/@me/profile', { ...submissionData, otp: authCode })
.then(res => {
console.log('2FA: Success');
.then(() => {
setSuccess(t('settings.security.successMessage'));
getUser()
.then(res => {
setUser(res);
console.log('User data refetched and updated in context:', res.data);
})
.catch(err => {
setError(err.response.data.error);
Expand Down
9 changes: 1 addition & 8 deletions frontend/src/context/ChatContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ export const ChatProvider = ({ children }) => {
const sendMessage = useCallback(message => {
if (socketChat.current && socketChat.current.readyState === WebSocket.OPEN) {
socketChat.current.send(message);
} else {
console.log('WebSocket for Chat is not open');
}
}, []);

Expand Down Expand Up @@ -127,9 +125,7 @@ export const ChatProvider = ({ children }) => {

socketChat.current = new WebSocket(WS_CHAT_URL + token);

socketChat.current.onopen = () => {
console.log('WebSocket for Chat connection opened')
};
socketChat.current.onopen = () => {};

socketChat.current.onmessage = event => {
const response = JSON.parse(event.data);
Expand Down Expand Up @@ -211,8 +207,6 @@ export const ChatProvider = ({ children }) => {
const newToken = await refreshToken();
if (newToken) {
connectWSChat();
} else {
console.log('Websocket for Chat failed to refresh the token');
}
}
};
Expand All @@ -223,7 +217,6 @@ export const ChatProvider = ({ children }) => {
return () => {
if (socketChat.current && socketChat.current.readyState === WebSocket.OPEN) {
socketChat.current.close();
console.log('WebSocket for Chat closed');
}
};
}, [addNotification, setIsRefetch, navigate]);
Expand Down
7 changes: 1 addition & 6 deletions frontend/src/context/RelationContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ const RelationProvider = ({ children }) => {

socketStatus.current = new WebSocket(WS_STATUS_URL + token);

socketStatus.current.onopen = () => {
console.log('WebSocket for Status connection opened');
};
socketStatus.current.onopen = () => {};

socketStatus.current.onmessage = event => {
const response = JSON.parse(event.data);
Expand All @@ -92,8 +90,6 @@ const RelationProvider = ({ children }) => {
const newToken = await refreshToken();
if (newToken) {
connectWSStatus();
} else {
console.log('Websocket for Status failed to refresh the token');
}
}
}
Expand All @@ -104,7 +100,6 @@ const RelationProvider = ({ children }) => {
return () => {
if (socketStatus.current && socketStatus.current.readyState === WebSocket.OPEN) {
socketStatus.current.close();
console.log('WebSocket for Status closed');
}
};
}, [setActivity]);
Expand Down
11 changes: 1 addition & 10 deletions frontend/src/context/TournamentContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ const TournamentProvider = ({ children }) => {
const sendMessage = useCallback((message) => {
if (socketTournament.current && socketTournament.current.readyState === WebSocket.OPEN) {
socketTournament.current.send(JSON.stringify(message));
} else {
console.log('WebSocket for Tournaments is not open');
}
}, []);

Expand Down Expand Up @@ -107,8 +105,6 @@ const TournamentProvider = ({ children }) => {
}).map(formatUserData),
});
}
console.log('TournamentContext.js: updateTournament', data);
console.log('TournamentContext.js: isJoin', isJoin);
}, [navigate, setUser]);

useEffect(() => {
Expand Down Expand Up @@ -138,7 +134,6 @@ const TournamentProvider = ({ children }) => {
socketTournament.current = new WebSocket(WS_TOURNAMENT_URL);

socketTournament.current.onopen = () => {
console.log('WebSocket for Tournament connection opened');
identify();
};

Expand All @@ -162,7 +157,6 @@ const TournamentProvider = ({ children }) => {
updateTournament(data.d, false);
break;
case 'TOURNAMENT_MATCH_BEGIN':
console.log('TournamentContext.js: upcoming matches', data.d.matches);
setTimeout(() => {
setResetMatch(data.d);
}, 3000);
Expand All @@ -181,7 +175,7 @@ const TournamentProvider = ({ children }) => {
navigate(`/tournaments/${data.d.tournamentID}/results`);
break;
default:
console.log('TournamentContext.js: Unhandled event:', data.e);
break;
}
};

Expand All @@ -195,8 +189,6 @@ const TournamentProvider = ({ children }) => {
if (newToken) {
connectWSTournament();
addNotification('info', tRef.current('game.tournaments.reconnectMessage'));
} else {
console.log('WebSocket for Tournaments failed to refresh the token');
}
}
};
Expand All @@ -208,7 +200,6 @@ const TournamentProvider = ({ children }) => {
if (heartbeatIntervalRef.current) clearInterval(heartbeatIntervalRef.current);
if (socketTournament.current && socketTournament.current.readyState === WebSocket.OPEN) {
socketTournament.current.close();
console.log('WebSocket for Tournaments closed');
}
};
}, [identify, heartbeat, navigate, updateTournament, addNotification]);
Expand Down

0 comments on commit a4a1a8f

Please sign in to comment.