clean all

This commit is contained in:
Alexandre POMMIER 2023-06-26 11:38:22 +02:00
parent c578ee926c
commit ad10c23528
16 changed files with 15 additions and 405 deletions

View File

@ -1,14 +1,14 @@
REACT_APP_BASE_URL=localhost:8080
REACT_APP_SOCKET_URL=localhost
REACT_APP_BASE_URL=paul-f4Ar4s3:8080
REACT_APP_SOCKET_URL=paul-f4Ar4s3
REACT_APP_API_SECRET=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
REACT_APP_CLIENT_UID=u-s4t2ud-6d29dfa49ba7146577ffd8bf595ae8d9e5aaa3e0a9615df18777171ebf836a41
REACT_APP_API_SECRET=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
REACT_APP_CLIENT_UID=u-s4t2ud-2bd3c5d4f41e776f2e3d5d699d2a8421f6d0c0468ec882516d9ca89b0c211789
# REACT_APP_BASE_URL=92.143.191.152
# REACT_APP_BASE_URL=192.168.1.19
REACT_APP_INTRA_URL="https://api.intra.42.fr/oauth/authorize?client_id=u-s4t2ud-6d29dfa49ba7146577ffd8bf595ae8d9e5aaa3e0a9615df18777171ebf836a41&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2Fapi%2Fauth%2Flogin&response_type=code"
REACT_APP_INTRA_URL="https://api.intra.42.fr/oauth/authorize?client_id=u-s4t2ud-2bd3c5d4f41e776f2e3d5d699d2a8421f6d0c0468ec882516d9ca89b0c211789&redirect_uri=http%3A%2F%2Fpaul-f4Ar4s3%3A8080%2Fapi%2Fauth%2Flogin&response_type=code"
# REACT_APP_BASE_URL=92.143.191.152
# REACT_APP_BASE_URL=192.168.1.19

View File

@ -1,5 +1,4 @@
import React from 'react';
// import './Header.scss';
function Footer() {
return (

View File

@ -4,23 +4,13 @@ import {Link} from 'react-router-dom';
import DefaultPicture from '../assets/profile.jpg'
import { motion, AnimatePresence } from 'framer-motion'
import Modal from './Sidebar/Modal.tsx';
import YellowAlert from './Alert/YellowAlert.tsx';
import '../styles/Header.css';
import api from '../script/axiosApi.tsx';
import { MdQrCodeScanner } from 'react-icons/md';
import { GiWingedSword, GiCrownedSkull } from 'react-icons/gi';
function Header() {
// const [sidebar, setSidebar] = useState(false);
// const showSidebar = () => setSidebar(!sidebar);
const [modalOpen, setModalOpen] = useState(false);
const close = () => setModalOpen(false);
const open = () => setModalOpen(true);
const [success, setSuccess] = useState([]);
const [profilePicture, setProfilePicture] = useState('');
useEffect(() => {
@ -29,9 +19,6 @@ function Header() {
const user = await api.get("/profile");
const pic = await api.post("/getPicture", {username: user.data.username})
setProfilePicture(pic.data);
// console.log("test ===", user.data)
setSuccess(user.data);
// console.log(`profile pic222= ${pic.data}`)
} catch (error) {
console.error('Error fetching profile picture:', error);
}
@ -54,9 +41,7 @@ function Header() {
<div>
{profilePicture ? (
// <img className='Header-pic' src={profilePicture} alt="Profile Picture" />
<img className='Header-pic' src={`data:image/jpeg;base64,${profilePicture}`} />
// <img className='Header-pic' src={`data:image/jpeg;base64,${profilePicture.data}`} alt="Profile Picture" />
) : (
<img className='Header-pic' src={DefaultPicture} alt="Default Profile Picture" />
)}

View File

@ -1,7 +1,4 @@
import { AnimatePresence, motion } from "framer-motion"
// import Backdrop from "../Sidebar/Backdrop"
import { Link } from 'react-router-dom';
// import { UserProfile } from "../../DataBase/DataUserProfile";
import { useState } from 'react';
import "../../styles/Profile.css"
@ -21,14 +18,7 @@ const dropIn = {
},
}
// const changeName = ({handleclose, name}) => {
// return (
// UserProfile.UserName = name
// )
// }
const ModalEdit = () => {
// let new_name = "";
const [nickname, setNickname] = useState("");
const [errTaken, setErrTaken] = useState(false);
const closeTaken = () => setErrTaken(false);
@ -37,56 +27,28 @@ const ModalEdit = () => {
const handler = (e: { target: { value: React.SetStateAction<string>; }; }) => {
setNickname(e.target.value);
console.log("testeeeee")
const postNickname = async () => {
// try{
// await api.post("/nickname", {nickname: nickname})
// // setUser(tmpUser.data);
// // setIsLoading(false)
// }
// catch(err){
// console.log(err);
// }
};
postNickname();
}
const handlePostNickname = async () => {
console.log("nickname=", nickname)
try {
// console.log("cest ici = ",ret);
// if (!ret)
// console.log("test ret =", ret.data);
if (nickname.length > 3) {
const ret = await api.post("/nickname", { nickname: nickname });
if (ret.data) {
console.log("ici error = ", ret.data);
window.location.reload();
}
else {
console.log("nickname already set = ", ret.data);
setErrTaken(true);
}
}
else if (nickname.length < 3)
{
setErrTooShort(true);
}
// setUser(tmpUser.data);
// setIsLoading(false)
}
catch (err) {
console.log(err);
}
}
// function handleClose(){
// //do nothing
// }
return (
<motion.div
className="modal"
@ -99,7 +61,6 @@ const ModalEdit = () => {
<div>
<div className="button" onClick={handlePostNickname}>
change
{/* <Link className="button" to={""}>change</Link> */}
</div>
<AnimatePresence initial={false} onExitComplete={() => null}>
{

View File

@ -16,10 +16,6 @@ function Logout(){
logout();
localStorage.clear();
const path = 'http://' + process.env.REACT_APP_BASE_URL + '/';
// history(path, { replace: true });
// window.location.replace(path);
// window.history.pushState({}, '', path);
window.history.pushState({}, '', path);
window.location.reload();
return (<></>)

View File

@ -1,50 +1,5 @@
// import PropTypes from "prop-types"
// import styled from 'styled-components';
// import '../DataBase/DummyDBWinLoss.js'
// import '../DataBase/DataProfileUser.js'
// import { DBWinLoss } from '../../DataBase/DummyDBWinLoss.js';
import '../../styles/Win_Loss.css'
import { User, Matchlog } from "../../../interfaces.tsx"
// import { UserProfile } from '../../DataBase/DataUserProfile';
// import color from '../../utils/style/color.js';
// const CardWrapper = styled.div`
// display: flex;
// flex-direction: column;
// padding: 15px;
// background-color: black;
// border-radius: 30px;
// width: 350px;
// transition: 200ms;
// margin-top: 50px;
// &:hover {
// cursor: pointer;
// box-shadow: 2px 2px 10px #b6b6b6;
// }
// `
// const CardLabel1 = styled.h1`
// color: #5843e4;
// // font-size: 22px;
// font-weight: bold;
// margin-bottom: 25px;
// `
// const CardLabel2 = styled.span`
// color: #5843e4;
// font-size: 22px;
// font-weight: bold;
// display: flex;
// flex-direction: column;
// `
// const CardImage = styled.img`
// heigh: 80px;
// width: 80px;
// border-radius: 50%;
// `
import React, { useState, useEffect, useRef } from "react";
import { useParams } from 'react-router-dom';
import api from '../../script/axiosApi.tsx';
@ -61,7 +16,6 @@ function WinLoss() {
useEffect(()=> {
const getUser = async ()=>{
try{
// const tmpUser = await api.get("/profile")
console.log("username win loss=", username)
let tmpUser;
let tmpHistory;
@ -87,23 +41,10 @@ function WinLoss() {
getUser();
}, [])
// console.log(`user= ${user.children}`)
return (
// <div>
// {isLoading ? (
// <h1>Loading...</h1>
// ) : (
// <h1>{user.username}</h1>
// )}
// </div>
<div className='tab'>
{isLoading || !history || !user ? (
<h1>Loading...</h1>
// <span>Loading...</span>
) : (
<div className='scroll'>
<h2 className='title'>Match history {user.win}/{user.loss}</h2>
@ -111,41 +52,17 @@ function WinLoss() {
return (
<div key={index} className='elements'>
<li key={index}>
{/* <h4 className='content'>{c.id}</h4> */}
<div className='content2nd'>
<h4 className='me'>{user.username}</h4> <h4 className='score'>{c.myScore} - {c.opScore} </h4> <h4 className="opponent">{c.opponent}</h4>
</div>
{/* <h4 className='content'>{c.openent}</h4> */}
</li>
</div>
)
})}
</div>
// <div>
// <h1>User: {user.name}</h1>
// <div>
// <h2>Children:</h2>
// {history.map((child) => (
// <div key={child.id}>
// <p>Child ID: {child.id}</p>
// <p>Child Name: {child.name}</p>
// {/* Render other child properties as needed */}
// </div>
// ))}
// </div>
// </div>
)}
</div>
)
}
// Card.propTypes = {
// label: PropTypes.string,
// title: PropTypes.string.isRequired,
// picture: PropTypes.string,
// }
export default WinLoss

View File

@ -1,4 +1,4 @@
import React, { MouseEventHandler, ReactNode, HTMLAttributes } from "react";
import React, { ReactNode } from "react";
import { motion } from "framer-motion"
import "../../styles/Header.css"

View File

@ -3,7 +3,6 @@ import api from '../script/axiosApi.tsx';
const DoubleAuth = () => {
// const [imageSrc, setImageSrc] = useState('');
const [imageSrc, setImageSrc] = useState<string | ArrayBuffer | null>('');
useEffect(() => {

View File

@ -16,7 +16,6 @@ function Field()
useEffect(() => {
const queryParams = queryString.parse(window.location.search);
console.log("launch canva hehe")
let Modifiers = 0;
let info: GameProps;
@ -38,19 +37,16 @@ function Field()
}
if (queryParams.username)
{
console.log("user= ", queryParams.username)
info = {
privateParty: true,
username: queryParams.username as string,
gameId: queryParams.gameId as unknown as number
}
console.log("info of param vefore canvas=", info)
info = {
privateParty: true,
username: queryParams.username as string,
gameId: queryParams.gameId as unknown as number
}
}
const cleanup = DrawCanvas(Modifiers, info);
return () => {
console.log("Cleanup");
if (cleanup)
cleanup();
};

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/09 08:19:04 by apommier #+# #+# */
/* Updated: 2023/06/26 07:06:35 by apommier ### ########.fr */
/* Updated: 2023/06/26 11:31:57 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -41,14 +41,11 @@ function Profile () {
const [profilePicture, setProfilePicture] = useState('');
const handleFileChange = async (event: { target: { files: any; }; }) => {
const photo = (event.target.files[0]);
console.log("file selected")
if (photo) {
console.log("selected photo")
const formData = new FormData();
formData.append('photo', photo);
try {
await api.post('/picture', formData);
console.log('File uploaded successfully');
window.location.reload();
} catch (error) {
setError(true);

View File

@ -6,7 +6,6 @@ function HomeLogin()
{
const handleButtonClick = () => {
const token = localStorage.getItem('token')
console.log(`token type= ${typeof token}`);
if (token !== null && typeof token === 'string')
return ;
let path = process.env.REACT_APP_INTRA_URL || "";

View File

@ -38,23 +38,13 @@ function DrawCanvas(option: number, gameParam: GameProps) {
function launchGame()
{
if (!gameParam.privateParty)
{
console.log("laucnh matchmaking")
matchmaking();
}
else if (!gameParam.gameId)
{
console.log("laucnh private")
privateParty();
}
else
{
console.log("join private")
joinPrivateParty();
}
}
console.log("start function");
const canvas = document.getElementById('myCanvas') as HTMLCanvasElement | null;
if (!canvas)
return ;
@ -131,13 +121,9 @@ function DrawCanvas(option: number, gameParam: GameProps) {
socket.on('pong:win', async () => {
myScore = maxScore;
console.log("instant win opponent disconnect")
console.log("after request1")
await api.post('/status', {status: 1});
console.log("after request2")
running = false;
socket.emit('pong:disconnect', {id: myId});
console.log("before reload")
return ;
});
@ -152,19 +138,13 @@ socket.on('pong:privateId', async (data) => {
});
socket.on('pong:gameId', async (data) => {
console.log("gameId received");
gameId = data.gameId;
console.log("gameid = ", gameId);
console.log("data gameid = ", data);
try {
let response = await api.get('/profile');
const myName = response.data.username;
response = await api.get('/rank');
await api.post('/status', {status: 2});
opRank = response.data
console.log(`rank= ${opRank}`);
console.log(`myname= ${myName}`);
const info = {
id: myId,
@ -173,18 +153,11 @@ socket.on('pong:gameId', async (data) => {
rank: opRank,
};
console.log("emit to name");
socket.emit('pong:name', info);
if (data.id === myId)
{
console.log("myId= true")
vX = 0.0005;
}
else
{
console.log("myId= false")
vX = -0.0005;
}
} catch (error) {
console.log(error);
return;
@ -193,7 +166,6 @@ socket.on('pong:gameId', async (data) => {
socket.on('pong:name', (data) => {
opName = data.name;
console.log(`opponent Name= ${opName}`)
});
socket.on('connect', () => {
@ -201,9 +173,7 @@ socket.on('connect', () => {
});
socket.on('pong:clientId', (data) => {
console.log("receive id")
myId = data;
console.log(`id is= ${myId}`)
launchGame();
});
@ -217,12 +187,10 @@ socket.on('pong:info', (data) => {
});
socket.on('pong:paddle', (data) => {
console.log("paddle info receive")
oPaddleY = (data.paddleY / data.height) * canvas.height
});
socket.on('pong:power', (data) => {
console.log("paddle info receive")
oPaddleY = 0;
opPaddleHeight = canvas.height;
@ -230,12 +198,10 @@ socket.on('pong:power', (data) => {
setTimeout(() => {
opPaddleHeight = canvas.height * 0.25;
oPaddleY = canvas.height / 2 - paddleHeight / 2;
console.log('Cinq secondes se sont écoulées.');
}, 5000);
});
socket.on('pong:point', (data) => {
console.log("gain point");
myScore = data.point;
vX = -0.0005;
vY = 0;
@ -244,7 +210,6 @@ socket.on('pong:point', (data) => {
});
socket.on('pong:hisPoint', (data) => {
console.log("myPointawdawdawdawd point");
hisScore = data.point;
vX = -0.0005;
vY = 0;
@ -260,7 +225,6 @@ socket.on('pong:hisPoint', (data) => {
function matchmaking()
{
console.log(`id ion matcj= ${myId}`)
const info = {
id: myId,
option: option,
@ -270,7 +234,6 @@ socket.on('pong:hisPoint', (data) => {
function privateParty()
{
console.log(`id private party= ${myId}`)
const info = {
id: myId,
option: option,
@ -280,7 +243,6 @@ socket.on('pong:hisPoint', (data) => {
function joinPrivateParty()
{
console.log(`id private party= ${myId}`)
const info = {
id: myId,
gameId: gameParam.gameId,
@ -311,7 +273,6 @@ socket.on('pong:hisPoint', (data) => {
{
if (!gameId || !canvas)
return ;
console.log("send point");
const info = {
id: myId,
gameId: gameId,
@ -391,7 +352,6 @@ socket.on('pong:hisPoint', (data) => {
function drawcenter()
{
// ctx.restore();
if (!ctx || !canvas)
return ;
ctx.fillStyle = 'white';
@ -459,18 +419,14 @@ socket.on('pong:hisPoint', (data) => {
opRank: opRank,
};
await api.post('/loss', data);
// await api.post('/status', {status: 1});
}
//here
socket.emit('pong:disconnect', {id: myId});
window.location.replace("http://" + process.env.REACT_APP_BASE_URL + "/pong");
};
async function draw(timestamp: number)
{
console.log("turning, running= ", running);
if (!running)
{
window.location.replace("http://" + process.env.REACT_APP_BASE_URL + "/pong")
@ -483,7 +439,6 @@ async function draw(timestamp: number)
}
if (myScore === maxScore || hisScore === maxScore)
{
console.log("maxScore!!!!")
const data = {
myScore: myScore,
opScore: hisScore,
@ -495,14 +450,12 @@ async function draw(timestamp: number)
await api.post('/win', data);
await api.post('/status', {status: 1});
socket.emit('pong:disconnect', {id: myId});
console.log("send all ?? win");
}
else
{
await api.post('/loss', data);
await api.post('/status', {status: 1});
socket.emit('pong:disconnect', {id: myId});
console.log("send loose");
}
window.location.replace("http://" + process.env.REACT_APP_BASE_URL + "/pong");
return ;
@ -567,10 +520,7 @@ async function draw(timestamp: number)
if (ballY <= paddleY + paddleHeight + ballRadius && ballY >= paddleY - ballRadius)//touch paddle
{
if (ballX + ballRadius > paddleX && ballX - ballRadius < paddleX + paddleWidth)
{
console.log("hehe here")
ballX = paddleX + paddleWidth + ballRadius;
}
updateVector();
}
send_info();
@ -594,7 +544,6 @@ async function draw(timestamp: number)
{
if (ballY <= paddleY + paddleHeight + ballRadius && ballY >= paddleY - ballRadius)
{
console.log('true hehe');
ballX = paddleX + paddleWidth + ballRadius;
updateVector();
return ;
@ -607,11 +556,7 @@ async function draw(timestamp: number)
send_point();
}
if (ballX > (canvas.width * 1.2) && ballX - (vX * 2) > canvas.width)
{
console.log("ball out win point pls")
send_my_point();
}
}
@ -672,7 +617,6 @@ async function draw(timestamp: number)
setTimeout(() => {
paddleHeight = canvas.height * 0.25;
paddleY = canvas.height / 2 - paddleHeight / 2;
console.log('Cinq secondes se sont écoulées.');
}, 5000);
date = new Date();
lastPower = date.getTime();
@ -680,7 +624,6 @@ async function draw(timestamp: number)
});
requestAnimationFrame(draw);
console.log("retuuuuuuuuuuurn")
return (stopDrawCanvas);
}

View File

@ -11,20 +11,9 @@ function getToken() {
console.log(`getToken = ${getToken()}`)
console.log(`Bearer ${localStorage.getItem("token")}`)
// const test = "192.168.1.19"
// const url = 'http://' + process.env.REACT_APP_BASE_URL + '/api'
// const url = 'http://' + test + '/api'
// console.log("url= ", url)
// console.log("test= ", test)
// console.log("env= ", process.env.REACT_APP_BASE_URL)
let api = axios.create({
// baseURL: 'http://localhost/api',
baseURL: 'http://' + process.env.REACT_APP_BASE_URL + '/api',
headers: {
// Authorization: `Bearer ${getToken()}`,
Authorization : `Bearer ${localStorage.getItem("token")}`
},
withCredentials: true,

View File

@ -1,13 +0,0 @@
// export const login()
// {
// alert("Le bouton a été cliqué !");
// var formulaire = document.getElementById("loginForm");
// formulaire.submit();
// }
export const login = () => {
console.log('Hello from myFunction');
// alert("Le bouton a été cliqué !");
var formulaire = document.getElementById("loginForm");
formulaire.submit();
}

View File

@ -1,7 +0,0 @@
// function setupLogin()
// {
// // alert("Le bouton a été cliqué !");
// console.log('Hello from login42');
// }
// export default setupLogin;

View File

@ -41,14 +41,9 @@ function SuccessToken() {
}, [data]);
const handleKeyPress = async (e: { key: string; })=>{
// console.log(`e in press= ${e.key}`)
if (e.key !== "Enter")
return ;
try{
console.log("code= ", code)
// const res = await api.post("/verifyOtp", {token: code})
const res = await axios({
method: 'POST',
url: 'http://' + process.env.REACT_APP_BASE_URL + '/api/verifyOtp',
@ -59,28 +54,13 @@ function SuccessToken() {
data: { token: code }
});
console.log("res= ", res.data)
console.log("res= ", res)
if (res.data === 1)
{
console.log("registered")
// history.push('/login')
localStorage.setItem('token', `${cleanData}`);
console.log(`prout token2= ${localStorage.getItem('token')}`);
window.location.replace("http://" + process.env.REACT_APP_BASE_URL + "/pong");
// const path = 'http://' + process.env.REACT_APP_BASE_URL + '/';
// window.history.pushState({}, '', path);
// window.location.reload();
}
else
{
console.log("bad code")
//alert ?? retry
}
// redirect('/test')
}
catch(err){
console.log(err)
@ -90,7 +70,6 @@ function SuccessToken() {
if (!user) {
// Render a loading indicator or return null while user is being fetched
return <h1>Loading...</h1>;
}
if (!data)
@ -98,9 +77,7 @@ function SuccessToken() {
const cleanData = data.slice(1, -1); // Declare cleanData here as well
if (!user.otp_verified) {
console.log("false");
localStorage.setItem('token', `${cleanData}`);
console.log(`prout token2= ${localStorage.getItem('token')}`);
window.location.replace("http://" + process.env.REACT_APP_BASE_URL + "/pong");
return null; // or return a message or component indicating not verified
}
@ -121,131 +98,3 @@ function SuccessToken() {
}
export default SuccessToken;
// function SuccessToken() {
// const location = useLocation();
// const { data } = queryString.parse(location.search);
// if ( !data)
// {
// console.log("no data")
// return ;
// }
// const cleanData = data.slice(1, -1);
// const [code, setCode] = useState('');
// const [user, setUser] = useState(false);
// useEffect(()=> {
// const getUser = async ()=>{
// try {
// // const tmpUser = await api.get("/profile");
// const tmpUser = await axios({
// method: 'GET',
// url: 'http://' + process.env.REACT_APP_BASE_URL + '/api/profile',
// headers: {
// Authorization: `Bearer ${cleanData}`,
// },
// withCredentials: true,
// });
// setUser(tmpUser.data);
// // setUser(tmpUser.data);
// // if (tmpUser.data.otp_verified)
// // {
// // console.log("true");
// // return (
// // <>
// // <h1>Double Auth</h1>
// // <input
// // onKeyDown={handleKeyPress}
// // type="text"
// // className="qr"
// // placeholder="6 Digits Code"
// // value={code}
// // onChange={(e) => setCode(e.target.value)}
// // />
// // </>
// // )
// // }
// // else
// // {
// // console.log("false");
// // localStorage.setItem('token', `${cleanData}`);
// // console.log(`prout token2= ${localStorage.getItem('token')}`)
// // window.location.replace("http://" + process.env.REACT_APP_BASE_URL + "/pong");
// // }
// } catch(err) {
// console.log(err)
// }
// }
// getUser();
// }, []);
// const handleKeyPress = async (e)=>{
// // console.log(`e in press= ${e.key}`)
// if (e.key !== "Enter")
// return ;
// try{
// console.log("code= ", code)
// const res = await api.post("/verifyOtp", {token: code})
// console.log("res= ", res.data)
// console.log("res= ", res)
// if (res.data === 1)
// {
// console.log("registered")
// // history.push('/login')
// const path = 'http://' + process.env.REACT_APP_BASE_URL + '/';
// window.history.pushState({}, '', path);
// window.location.reload();
// }
// else
// {
// console.log("bad code")
// //alert ?? retry
// }
// // redirect('/test')
// }
// catch(err){
// console.log(err)
// }
// }
// console.log("start while...")
// while(user === false)
// ;
// console.log("end while")
// if (!user.otp_verified)
// {
// console.log("false");
// localStorage.setItem('token', `${cleanData}`);
// console.log(`prout token2= ${localStorage.getItem('token')}`)
// window.location.replace("http://" + process.env.REACT_APP_BASE_URL + "/pong");
// return ;
// }
// return (
// <>
// <h1>Double Auth</h1>
// <input
// onKeyDown={handleKeyPress}
// type="text"
// className="qr"
// placeholder="6 Digits Code"
// value={code}
// onChange={(e) => setCode(e.target.value)}
// />
// </>
// )
// }
// export default SuccessToken;