diff --git a/src/components/PreviewUpload.tsx b/src/components/PreviewUpload.tsx index 218dcf0..cb092b4 100644 --- a/src/components/PreviewUpload.tsx +++ b/src/components/PreviewUpload.tsx @@ -1,10 +1,29 @@ -import React, { useState } from 'react'; +import React, { useContext, useState } from 'react'; +import { Axios, ResponseT, UserCtx, UserCtxT } from '../context/UserContext'; function PreviewUpload({chgFile}:{chgFile: any}) { const [file, setFile] = useState(undefined); const [dimensionWidth, setDimensionWidth] = useState(0); const [dimensionHeight, setDimensionHeight] = useState(0); + const { user } = useContext(UserCtx) as UserCtxT; + const [dog, setDog] = useState({}); // local dog not the dog in UserContext + + if(user && (dog === undefined || dog.success === undefined)) + { + Axios.post('getDog.php', + { + qr_id: user.qr_id + }) + .then((resDog) => + { + setDog(resDog.data); + setFile("./uploads"+resDog.data.data.picture); + }) + .catch((err) => console.error(err)); + } + + const handleChange = async ( event: React.ChangeEvent ): Promise => { diff --git a/src/components/Profil.tsx b/src/components/Profil.tsx index c43b047..ee6c45b 100644 --- a/src/components/Profil.tsx +++ b/src/components/Profil.tsx @@ -1,5 +1,7 @@ import React, { useContext, useState } from 'react' +import { Link } from 'react-router-dom'; import { Axios, ResponseT, UserCtx, UserCtxT } from '../context/UserContext'; +import Img from './Img'; import './Profil.css'; function Profil() @@ -68,6 +70,10 @@ function Profil() return (

Profil

+
+ {dog.data && } + Bild ändern +