"use client"; import Image from "next/image"; import Link from "next/link"; import { useEffect, useState } from "react"; interface Announcement { id: number; title: string; content: string; createdAt: string; } interface GalleryPost { id: number; title: string; createdAt: string; thumbnailUrl?: string; } export default function NewsAndGalleryClient() { const [newsItems, setNewsItems] = useState([]); const [galleryPosts, setGalleryPosts] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { async function fetchData() { try { const [announcementsRes, galleryRes] = await Promise.all([ fetch('/api/announcements?limit=6'), fetch('/api/gallery?limit=4'), ]); const [announcementsData, galleryData] = await Promise.all([ announcementsRes.json(), galleryRes.json(), ]); setNewsItems(announcementsData.data || []); // 갤러리 썸네일 URL 가져오기 const galleryWithUrls = await Promise.all( (galleryData.data || []).map(async (post: GalleryPost & { images?: Array<{ fileKey: string }> }) => { if (post.images?.[0]?.fileKey) { const urlRes = await fetch('/api/files/download-url', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ fileKey: post.images[0].fileKey }), }); const urlData = await urlRes.json(); return { ...post, thumbnailUrl: urlData.data?.downloadUrl }; } return post; }) ); setGalleryPosts(galleryWithUrls); } catch (error) { console.error('Failed to fetch data:', error); } finally { setLoading(false); } } fetchData(); }, []); const formatDate = (dateString: string) => { const date = new Date(dateString); const day = date.getDate().toString().padStart(2, '0'); const month = (date.getMonth() + 1).toString().padStart(2, '0'); const year = date.getFullYear(); return { day, date: `${year}.${month}` }; }; return (
{/* 왼쪽: 소식 */}

News

소식

{loading ? ( Array.from({ length: 4 }).map((_, index) => (
)) ) : newsItems.length > 0 ? ( newsItems.slice(0, 6).map((item, index) => { const { day, date } = formatDate(item.createdAt); return ( = 4 ? 'hidden smalltablet:block' : ''}`} >
{day}
{date}

{item.title}

{item.content}

); }) ) : (
아직 공지사항이 없습니다.
)}
{/* 오른쪽: 갤러리 */}

Photos

앨범

{loading ? ( Array.from({ length: 3 }).map((_, index) => (
)) ) : galleryPosts.length > 0 ? ( galleryPosts.map((post) => { const { date } = formatDate(post.createdAt); return (
{post.thumbnailUrl ? ( {post.title} ) : (
No Image
)}

{post.title}

{date}

); }) ) : (
아직 갤러리가 없습니다.
)}
); }