Skip to content

Commit

Permalink
Try still fix esl errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Draikth committed Jul 25, 2024
1 parent fb346bd commit 1978f1b
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 134 deletions.
65 changes: 0 additions & 65 deletions app/imageUpload/ImageForm.tsx

This file was deleted.

138 changes: 69 additions & 69 deletions app/imageUpload/ImgUpload.tsx
Original file line number Diff line number Diff line change
@@ -1,81 +1,38 @@
import Image from 'next/image';
import { useEffect, useState } from 'react';
import ImageForm from './ImageForm';

type ImageUploadPageProps = {
onImageSelect: (url: string) => void;
};

type ImageType = {
id: number;
url: string;
};

export default function ImageUploadPage({
onImageSelect,
}: ImageUploadPageProps) {
const [images, setImages] = useState<ImageType[]>([]);
const [error, setError] = useState<string | null>(null);

useEffect(() => {
async function fetchImages() {
try {
const response = await fetch('/api/fetchImages');
if (!response.ok) {
throw new Error('Failed to fetch images');
}
const data = await response.json();
setImages(data);
} catch (err) {
setError('Failed to load images');
console.error('Error fetching images:', error);
}
}
fetchImages();
}, []);

return (
<div>
<div>
<h1>Upload Image to Cloudinary</h1>

{images.length > 0 && (
<div>
<h2>Images</h2>
<ul>
{images.map((image) => (
<li key={`image-${image.id}`}>
<Image
src={image.url}
alt="Uploaded image"
width={80}
height={100}
onClick={() => onImageSelect(image.url)}
style={{ cursor: 'pointer' }}
/>
</li>
))}
</ul>
</div>
)}
<ImageForm buttonTitle="Upload Image" formTitle="Upload Image" />
</div>
</div>
);
}

// import Image from 'next/image';
// import { getImagesInsecure } from '../../database/imgQueries';
// import { useEffect, useState } from 'react';
// import ImageForm from './ImageForm';

// type ImageUploadPageProps = {
// onImageSelect: (url: string) => void;
// };

// export default async function ImageUploadPage({
// type ImageType = {
// id: number;
// url: string;
// };

// export default function ImageUploadPage({
// onImageSelect,
// }: ImageUploadPageProps) {
// const images = await getImagesInsecure();
// const [images, setImages] = useState<ImageType[]>([]);
// const [error, setError] = useState<string | null>(null);

// useEffect(() => {
// async function fetchImages() {
// try {
// const response = await fetch('/api/fetchImages');
// if (!response.ok) {
// throw new Error('Failed to fetch images');
// }
// const data = await response.json();
// setImages(data);
// } catch (err) {
// setError('Failed to load images');
// console.error('Error fetching images:', error);
// }
// }
// fetchImages();
// }, []);

// return (
// <div>
Expand Down Expand Up @@ -106,3 +63,46 @@ export default function ImageUploadPage({
// </div>
// );
// }

// // import Image from 'next/image';
// // import { getImagesInsecure } from '../../database/imgQueries';
// // import ImageForm from './ImageForm';

// // type ImageUploadPageProps = {
// // onImageSelect: (url: string) => void;
// // };

// // export default async function ImageUploadPage({
// // onImageSelect,
// // }: ImageUploadPageProps) {
// // const images = await getImagesInsecure();

// // return (
// // <div>
// // <div>
// // <h1>Upload Image to Cloudinary</h1>

// // {images.length > 0 && (
// // <div>
// // <h2>Images</h2>
// // <ul>
// // {images.map((image) => (
// // <li key={`image-${image.id}`}>
// // <Image
// // src={image.url}
// // alt="Uploaded image"
// // width={80}
// // height={100}
// // onClick={() => onImageSelect(image.url)}
// // style={{ cursor: 'pointer' }}
// // />
// // </li>
// // ))}
// // </ul>
// // </div>
// // )}
// // <ImageForm buttonTitle="Upload Image" formTitle="Upload Image" />
// // </div>
// // </div>
// // );
// // }

0 comments on commit 1978f1b

Please sign in to comment.