-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
last commit before video if no errors
Showing
6 changed files
with
134 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
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 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> | ||
// ); | ||
// } |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
import { Sql } from 'postgres'; | ||
import { z } from 'zod'; | ||
// import { Sql } from 'postgres'; | ||
// import { z } from 'zod'; | ||
|
||
export type EvImage = { | ||
id: number; | ||
url: string; | ||
}; | ||
// export type EvImage = { | ||
// id: number; | ||
// url: string; | ||
// }; | ||
|
||
export const imageSchema = z.object({ | ||
url: z.string().url(), | ||
}); | ||
// export const imageSchema = z.object({ | ||
// url: z.string().url(), | ||
// }); | ||
|
||
export async function up(sql: Sql) { | ||
await sql` | ||
CREATE TABLE image_uploads ( | ||
id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY, | ||
url varchar(255) NOT NULL | ||
); | ||
`; | ||
} | ||
// export async function up(sql: Sql) { | ||
// await sql` | ||
// CREATE TABLE image_uploads ( | ||
// id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY, | ||
// url varchar(255) NOT NULL | ||
// ); | ||
// `; | ||
// } | ||
|
||
export async function down(sql: Sql) { | ||
await sql`DROP TABLE image_uploads`; | ||
} | ||
// export async function down(sql: Sql) { | ||
// await sql`DROP TABLE image_uploads`; | ||
// } |