pull pour debug avec le user null 🐛

pull/83/head
Pierre Ferreira 1 year ago
parent 9e98f374e9
commit 398d6a6e73

@ -2,28 +2,34 @@ import React, { useState } from 'react';
import '../Pages/Profile.css' import '../Pages/Profile.css'
import dl from '../res/icon/download.png' import dl from '../res/icon/download.png'
import defaultImg from '../res/img/Person.png' import defaultImg from '../res/img/Person.png'
import { useAuth } from '../Contexts/AuthContext';
//@ts-ignore //@ts-ignore
const ProfilePDP = ({ player}) => { const ProfilePDP = ({ player}) => {
const [selectedFile, setSelectedFile] = useState(null); const [selectedFile, setSelectedFile] = useState(null);
// @ts-ignore
const {user} = useAuth()
console.log(user)
// @ts-ignores
const handleFileChange = (event) => { const handleFileChange = (event) => {
let file = event.target.files[0]; let file = event.target.files[0];
setSelectedFile(file); setSelectedFile(file);
if (file) { if (file) {
const pdpUrl = URL.createObjectURL(file); const pdpUrl = URL.createObjectURL(file);
player.pdp = pdpUrl if (user!=null){
user.profilePicture = pdpUrl
}
} }
}; };
//! gitans ? //! gitans ?
if (player.pdp == undefined){ if (user == null){
player.pdp = defaultImg; console.log("duuude");
} }
console.log("pdp joueur " + player.pdp) console.log(user)
return ( return (
<div className='mainPDPContainer'> <div className='mainPDPContainer'>
{selectedFile ? ( {selectedFile ? (
@ -34,7 +40,7 @@ const ProfilePDP = ({ player}) => {
</div> </div>
) : ( ) : (
<div > <div >
<img src={player.pdp} alt="Preview" className='imgContainer' width='100px' height='100px' /> <img src={user?.profilePicture} alt="Preview" className='imgContainer' width='100px' height='100px' />
</div> </div>
)} )}
<div className="parent"> <div className="parent">

@ -22,8 +22,8 @@ const AuthProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
setIsLoggedIn(true); setIsLoggedIn(true);
}; };
const setUserData = (player: User | null) => { const setUserData = (newPlayer: User) => {
setUser(player) setUser(newPlayer)
} }
const logout = async() => { const logout = async() => {

@ -73,6 +73,9 @@ function Play() {
}, [isLoggedIn]); }, [isLoggedIn]);
useEffect(() => {
}, [user])
const { setIndicesData, setPersonData, setPersonNetworkData } = useGame(); const { setIndicesData, setPersonData, setPersonNetworkData } = useGame();

@ -7,41 +7,27 @@ import './Profile.css'
import SessionService from '../services/SessionService'; import SessionService from '../services/SessionService';
import { PlayerProps } from '../types/Player'; import { PlayerProps } from '../types/Player';
import { update } from 'lodash'; import { update } from 'lodash';
import Human from '../model/Human'; import User from '../model/User';
import { socket } from '../SocketConfig';
import { useAuth } from '../Contexts/AuthContext';
//@ts-ignore //@ts-ignore
const Profile = () => { const Profile = () => {
//let player; //let player;
const [player, setPlayer] = useState<Human>(new Human("null", "nullHuman")); const {user} = useAuth()
//! useeffect pour l'instant, il faudra voir pour changer la facons de prendre une session //! useeffect pour l'instant, il faudra voir pour changer la facons de prendre une session
useEffect(() => { useEffect(() => {
const fetchUserInformation = async () => { console.log(user)
try { }, [user])
const sessionData = await SessionService.getSession();
if (sessionData.user) {
const updatedPlayer: Human = {
name: sessionData.user.pseudo,
pdp: sessionData.user.profilePicture,
toJson: function (): { type: string; id: string; name: string; } {
throw new Error('Function not implemented.');
},
id: ''
};
setPlayer(updatedPlayer);
}
} catch (error) {
console.error(error);
}
}
fetchUserInformation();
}, []
)
return ( return (
<div className='mainContainer'> <div className='mainContainer'>
<ProfilePDP player={player}/> <ProfilePDP player={user}/>
<h1> {player.name} </h1> <h1> {user?.pseudo} </h1>
</div> </div>
); );
}; };

@ -1,16 +1,18 @@
import Player from "./Player"; import Player from "./Player";
import defaultpdp from "../res/img/Person.png"
class User extends Player{ class User extends Player{
public soloStats: any public soloStats: any
public onlineStats: any public onlineStats: any
constructor(id: string, name: string, profilePicture: string, soloStats: any, onlineStats: any){ constructor(id: string, pseudo: string, profilePicture: string = defaultpdp, soloStats: any, onlineStats: any){
super(id, name, profilePicture) super(id, pseudo, profilePicture)
this.soloStats=soloStats this.soloStats=soloStats
this.onlineStats=onlineStats this.onlineStats=onlineStats
} }
toJson() { toJson() {
return { return {
type: "User", type: "User",

Loading…
Cancel
Save