import React, { useState } from "react"; import Image from "next/image"; import useSWR from "swr"; import { Dialog, Transition } from "@headlessui/react"; // services import fileService from "services/file.service"; // ui import { Button, Input, Spinner } from "components/ui"; type Props = { isOpen: boolean; handleClose: () => void; onSelect: (url: string) => void; }; export const UnsplashImageModal: React.FC = (props) => { const { isOpen, handleClose, onSelect } = props; const [searchQuery, setSearchQuery] = useState(""); const [formData, setFormData] = useState({ search: "", }); const { data: images } = useSWR(`UNSPLASH_IMAGES_${searchQuery.toUpperCase()}`, () => fileService.getUnsplashImages(1, searchQuery) ); const onClose = () => { handleClose(); }; return (
Select an image
{ e.preventDefault(); setSearchQuery(formData.search); }} className="flex items-center" > setFormData({ ...formData, search: e.target.value })} placeholder="Search for images" />
{images ? (
{images.map((image) => ( ))}
) : (
)}
); };