useSWR upload
This commit is contained in:
@ -1,28 +1,25 @@
|
||||
// import React, { useContext, useState } from 'react';
|
||||
// import { ResponseT, UserCtx, UserCtxT } from '../context/UserContext';
|
||||
// import {Axios} from '../services/PhpApi';
|
||||
import React, { useState } from 'react';
|
||||
import { ResponseT } from '../context/UserContext';
|
||||
import {Axios, getDog} from '../services/PhpApi';
|
||||
import useSWR from 'swr';
|
||||
|
||||
function PreviewUpload({chgFile}:{chgFile: any}) {
|
||||
// const [file, setFile] = useState<string | undefined >(undefined);
|
||||
// const [dimensionWidth, setDimensionWidth] = useState(0);
|
||||
// const [dimensionHeight, setDimensionHeight] = useState(0);
|
||||
function PreviewUpload({chgFile}:{chgFile: any})
|
||||
{
|
||||
const [file, setFile] = useState<string | undefined >(undefined);
|
||||
const [dimensionWidth, setDimensionWidth] = useState(0);
|
||||
const [dimensionHeight, setDimensionHeight] = useState(0);
|
||||
|
||||
// const { user } = useContext<UserCtxT | null>(UserCtx) as UserCtxT;
|
||||
// const [dog, setDog] = useState<ResponseT | any>({}); // local dog not the dog in UserContext
|
||||
const [dog, setDog] = useState<ResponseT | any>({}); // local dog not the dog in UserContext
|
||||
|
||||
// if(user && (dog === undefined || dog.success === undefined))
|
||||
// {
|
||||
// Axios.post<ResponseT>('getDog.php',
|
||||
// {
|
||||
// qr_id: user.qr_id
|
||||
// })
|
||||
// .then((resDog) =>
|
||||
// {
|
||||
// setDog(resDog.data);
|
||||
// setFile("./uploads"+resDog.data.data.picture);
|
||||
// })
|
||||
// .catch((err) => console.error(err));
|
||||
// }
|
||||
const { data, error, isLoading } = useSWR(['PreviewUpload', 'SESS'], getDog );
|
||||
if (error) return (<div>failed to load</div>);
|
||||
if (isLoading) return (<div>loading...</div>);
|
||||
|
||||
console.log('PreviewUpload getDog');
|
||||
console.log(data);
|
||||
|
||||
setDog(data.data);
|
||||
setFile("./uploads"+ data.data.picture);
|
||||
|
||||
|
||||
// const handleChange = async (
|
||||
@ -32,7 +29,7 @@ function PreviewUpload({chgFile}:{chgFile: any}) {
|
||||
// // const img = new Image();
|
||||
// const ImageName = event.target.value.split('\\')[2];
|
||||
// const Image = event.target.value;
|
||||
// console.log('Imageon Kevel: ', Image); // Image on Kevel
|
||||
// console.log('Image on Kevel: ', Image); // Image on Kevel
|
||||
// console.log('ImageName on Kevel: ', ImageName); // ImageName on Kevel
|
||||
// console.log('ImageLink on Kevel: ', event.target.value); // ImageLink on Kevel
|
||||
// console.log('event current Target files: ', event.target.files![0]);
|
||||
@ -92,3 +89,4 @@ function PreviewUpload({chgFile}:{chgFile: any}) {
|
||||
// );
|
||||
}
|
||||
export default PreviewUpload;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user