From 398d6a6e737e98f37180d0fb27dec7cb5f31dd3f Mon Sep 17 00:00:00 2001 From: Pierre Ferreira Date: Fri, 24 Nov 2023 11:04:34 +0100 Subject: [PATCH] pull pour debug avec le user null :bug: --- .../src/Components/ProfilePDP.tsx | 18 ++++++---- cryptide_project/src/Contexts/AuthContext.tsx | 4 +-- cryptide_project/src/Pages/Play.tsx | 3 ++ cryptide_project/src/Pages/Profile.tsx | 36 ++++++------------- cryptide_project/src/model/User.tsx | 6 ++-- 5 files changed, 32 insertions(+), 35 deletions(-) diff --git a/cryptide_project/src/Components/ProfilePDP.tsx b/cryptide_project/src/Components/ProfilePDP.tsx index b681dd8..1b50d55 100644 --- a/cryptide_project/src/Components/ProfilePDP.tsx +++ b/cryptide_project/src/Components/ProfilePDP.tsx @@ -2,28 +2,34 @@ import React, { useState } from 'react'; import '../Pages/Profile.css' import dl from '../res/icon/download.png' import defaultImg from '../res/img/Person.png' +import { useAuth } from '../Contexts/AuthContext'; //@ts-ignore const ProfilePDP = ({ player}) => { const [selectedFile, setSelectedFile] = useState(null); - // @ts-ignore + + const {user} = useAuth() + console.log(user) + // @ts-ignores const handleFileChange = (event) => { let file = event.target.files[0]; setSelectedFile(file); if (file) { const pdpUrl = URL.createObjectURL(file); - player.pdp = pdpUrl + if (user!=null){ + user.profilePicture = pdpUrl + } } }; //! gitans ? - if (player.pdp == undefined){ - player.pdp = defaultImg; + if (user == null){ + console.log("duuude"); } - console.log("pdp joueur " + player.pdp) + console.log(user) return (
{selectedFile ? ( @@ -34,7 +40,7 @@ const ProfilePDP = ({ player}) => {
) : (
- Preview + Preview
)}
diff --git a/cryptide_project/src/Contexts/AuthContext.tsx b/cryptide_project/src/Contexts/AuthContext.tsx index a061775..7e27f05 100644 --- a/cryptide_project/src/Contexts/AuthContext.tsx +++ b/cryptide_project/src/Contexts/AuthContext.tsx @@ -22,8 +22,8 @@ const AuthProvider: React.FC<{ children: ReactNode }> = ({ children }) => { setIsLoggedIn(true); }; - const setUserData = (player: User | null) => { - setUser(player) + const setUserData = (newPlayer: User) => { + setUser(newPlayer) } const logout = async() => { diff --git a/cryptide_project/src/Pages/Play.tsx b/cryptide_project/src/Pages/Play.tsx index 257177a..38648f3 100644 --- a/cryptide_project/src/Pages/Play.tsx +++ b/cryptide_project/src/Pages/Play.tsx @@ -73,6 +73,9 @@ function Play() { }, [isLoggedIn]); + useEffect(() => { + }, [user]) + const { setIndicesData, setPersonData, setPersonNetworkData } = useGame(); diff --git a/cryptide_project/src/Pages/Profile.tsx b/cryptide_project/src/Pages/Profile.tsx index 5d7342a..b257359 100644 --- a/cryptide_project/src/Pages/Profile.tsx +++ b/cryptide_project/src/Pages/Profile.tsx @@ -7,41 +7,27 @@ import './Profile.css' import SessionService from '../services/SessionService'; import { PlayerProps } from '../types/Player'; 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 const Profile = () => { //let player; - const [player, setPlayer] = useState(new Human("null", "nullHuman")); + const {user} = useAuth() + //! useeffect pour l'instant, il faudra voir pour changer la facons de prendre une session + useEffect(() => { - const fetchUserInformation = async () => { - try { - 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(); - }, [] - ) + console.log(user) + }, [user]) return (
- -

{player.name}

+ +

{user?.pseudo}

); }; diff --git a/cryptide_project/src/model/User.tsx b/cryptide_project/src/model/User.tsx index ee287a8..6f61a1d 100644 --- a/cryptide_project/src/model/User.tsx +++ b/cryptide_project/src/model/User.tsx @@ -1,15 +1,17 @@ import Player from "./Player"; +import defaultpdp from "../res/img/Person.png" class User extends Player{ public soloStats: any public onlineStats: any - constructor(id: string, name: string, profilePicture: string, soloStats: any, onlineStats: any){ - super(id, name, profilePicture) + constructor(id: string, pseudo: string, profilePicture: string = defaultpdp, soloStats: any, onlineStats: any){ + super(id, pseudo, profilePicture) this.soloStats=soloStats this.onlineStats=onlineStats } + toJson() { return {