Skip to content

Commit

Permalink
last commit before video if no errors
Browse files Browse the repository at this point in the history
Draikth committed Jul 25, 2024
1 parent a25f93a commit 653ff79
Showing 6 changed files with 134 additions and 72 deletions.
108 changes: 108 additions & 0 deletions app/imageUpload/ImgUpload.tsx
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>
// );
// }
34 changes: 0 additions & 34 deletions app/imageUpload/page.tsx

This file was deleted.

18 changes: 3 additions & 15 deletions app/post/PostEventForm.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use client';

import Link from 'next/link';
import { useRouter } from 'next/navigation';
import { ChangeEvent, useState } from 'react';
import { PostEventsResponseBodyPost } from '../api/postedEvents/route';
@@ -30,12 +29,6 @@ export default function PostEventForm(props: Props) {

const router = useRouter();

function addImageUrl(url: string) {
setPostEvent({ ...postEvent, image: url });
}

console.log(addImageUrl);

async function handleCreate(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault();

@@ -65,7 +58,7 @@ export default function PostEventForm(props: Props) {
return;
}

router.push('/');
router.push('/events');
}

function handleChange(
@@ -95,13 +88,8 @@ export default function PostEventForm(props: Props) {
<br />
<form onSubmit={handleCreate}>
<div>
<div>
<h3>Upload Image</h3>
</div>
<Link href="/imageUpload">Poster for Event</Link>

{/* <label htmlFor="image">Upload Image: </label>
<input
<label htmlFor="image">Upload Image: </label>
{/* <input
id="image"
name="image"
value={postEvent.image}
2 changes: 1 addition & 1 deletion app/profile/[username]/DeleteProfileForm.tsx
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ export default function DeleteProfileForm({
const handleDelete = async (event: React.FormEvent) => {
event.preventDefault();

const response = await fetch('/api/postedEvents/deleteEvent', {
const response = await fetch('/api/user/delete', {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
4 changes: 2 additions & 2 deletions database/events.ts
Original file line number Diff line number Diff line change
@@ -31,8 +31,8 @@ export const eventSchema = z.object({
entryFee: z.number(),
category: z.string(),
description: z.string(),
organizerUrl: z.string().url(),
image: z.string().url(),
organizerUrl: z.string(),
image: z.string(),
ageRestriction: z.boolean(),
archived: z.boolean(),
});
40 changes: 20 additions & 20 deletions migrations/00008-createTableImageUpload.ts
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`;
// }

0 comments on commit 653ff79

Please sign in to comment.