This commit is contained in:
Janis
2023-02-05 19:58:46 +01:00
parent 8b8d75ca65
commit d41c8be336
25 changed files with 447 additions and 93 deletions

27
components/Gallery.tsx Normal file
View File

@@ -0,0 +1,27 @@
"use client";
import React, { useState } from "react";
import { Gallery as ReactGridGallery, Image as ImageType, ThumbnailImageProps } from "react-grid-gallery";
import Image from "next/image";
const ImageComponent = (props: ThumbnailImageProps) => {
const { src, alt, style, title } = props.imageProps;
const { width, height } = props.item;
return (
<Image
alt={alt}
src={src}
title={title || ""}
width={width}
height={height}
onClick={() => {
window.open(src);
}}
style={style}
/>
);
};
export default function Gallery({ images }: { images: ImageType[] }) {
return <ReactGridGallery images={images} enableImageSelection={false} thumbnailImageComponent={ImageComponent} />;
}

View File

@@ -0,0 +1,32 @@
/* eslint-disable @next/next/no-img-element */
"use client";
import React, { useState } from "react";
import { useRef } from "react";
export default function ImageUpload() {
const [selectedImage, setSelectedImage] = useState(null);
const inputRef = useRef<HTMLInputElement>(null);
const handleImageChange = (event) => {
setSelectedImage(URL.createObjectURL(event.target.files[0]));
};
async function uploadImage() {
if (selectedImage) {
const formData = new FormData();
formData.append("image", selectedImage);
const response = await fetch("/api/images/", {
method: "POST",
body: formData,
});
console.log(await response.json());
}
}
return (
<div>
<input onChange={handleImageChange} ref={inputRef} type="file" name="image" accept="image/*" />
{selectedImage && <img src={selectedImage} alt="Selected" />}
<button onClick={uploadImage}>Upload</button>
</div>
);
}