diff --git a/frontend/src/api/client.js b/frontend/src/api/client.js index b19011b..1e53ee1 100644 --- a/frontend/src/api/client.js +++ b/frontend/src/api/client.js @@ -1,8 +1,16 @@ export async function api(url, options = {}) { + const headers = { 'Content-Type': 'application/json', ...options.headers } + + // 관리자 API에는 인증 헤더 자동 추가 + if (url.startsWith('/api/admin')) { + const adminKey = localStorage.getItem('maple-admin-key') + if (adminKey) headers['x-admin-key'] = adminKey + } + const res = await fetch(url, { credentials: 'include', - headers: { 'Content-Type': 'application/json', ...options.headers }, ...options, + headers, body: options.body ? JSON.stringify(options.body) : undefined, }) diff --git a/frontend/src/features/admin/AdminImages.jsx b/frontend/src/features/admin/AdminImages.jsx index e5ed85c..cbc3b66 100644 --- a/frontend/src/features/admin/AdminImages.jsx +++ b/frontend/src/features/admin/AdminImages.jsx @@ -1,13 +1,282 @@ -export default function AdminImages() { +import { useState, useEffect, useRef } from 'react' +import { api } from '../../api/client' + +function UploadModal({ open, onClose, onUpload, uploading }) { + const [file, setFile] = useState(null) + const [name, setName] = useState('') + const [preview, setPreview] = useState(null) + const fileInputRef = useRef(null) + const [dragOver, setDragOver] = useState(false) + + useEffect(() => { + if (!open) { + setFile(null) + setName('') + setPreview(null) + } + }, [open]) + + const handleFile = (f) => { + if (!f || !f.type.startsWith('image/')) return + setFile(f) + setName(f.name.replace(/\.[^.]+$/, '')) + const reader = new FileReader() + reader.onload = (e) => setPreview(e.target.result) + reader.readAsDataURL(f) + } + + const handleSubmit = async (e) => { + e.preventDefault() + if (!file || !name.trim()) return + await onUpload({ file, name: name.trim() }) + } + + if (!open) return null + return ( -
공용 이미지를 업로드하고 관리합니다
-공용 이미지를 업로드하고 관리합니다
++ {images.length === 0 ? '업로드된 이미지가 없습니다' : '검색 결과가 없습니다'} +
+ {images.length === 0 && ( + + )} +