import React, { FormEvent, useEffect, useState } from "react"; import { mainimgApi } from "../apis"; import { catchErrors } from "../helpers"; import { MainimgType } from "../types"; import {MySlide} from "./adminslide"; export default function Admin() { const [getimgs, setGetimgs] = useState([]); async function imgsData() { const imgs = await mainimgApi.getmainimg(); // console.log("ㅑㅡㅎ", imgs) setGetimgs(imgs) }; useEffect(() => { imgsData(); }, []); const [addimg, setAddimg] = useState({ theme: "", city: "", url: "", title: "", }); const [loading, setLoading] = useState(false); const [error, setError] = useState(""); const [success, setSuccess] = useState(false); function handleSelectChange(event: React.ChangeEvent) { const { name, value } = event.currentTarget; setAddimg({ ...addimg, [name]: value }); } function handleInputeChange(event: React.ChangeEvent) { const { name, value } = event.currentTarget; setAddimg({ ...addimg, [name]: value }); } // console.log("asdafsdfs", getimgs) async function handleSubmit(event: FormEvent) { event.preventDefault(); try { setError(""); console.log("img data", addimg); setLoading(true); const res = await mainimgApi.mainimg(addimg); console.log("서버연결됬나요", res); setSuccess(true); setError(""); } catch (error) { console.log("에러발생"); catchErrors(error, setError); } finally { setLoading(false); } } if (success) { alert("img 추가되었습니다"); } let limit = 15; const numPages = Math.ceil(getimgs.length / 15); const slides = [] for (let i = 0; i < numPages; i++) { const k = [ getimgs.slice(i * limit, i * limit + limit).map((pic, index: number) => (

{pic.title}

))] slides.push(k); } return (

url

{/* type="file"/> */}

title

); };