// === import === import EventCard from '@/components/aia/event-card'; import { useState, useEffect, useRef } from 'react'; import { landing } from '/data/www/aia-official-en-main/web/src/js/index.js';// 重新 pull 的時候 要重新把 landing 改為 export 的函數 import { getNewsData } from '@/lib/utils'; import { carousel } from '/data/www/aia-official-en-main/web/src/js/patterns/carousel.js';// 重新 pull 的時候 要重新把 landing 改為 export 的函數 type LatestProps = { landingEvents: Array<{ eventCardTitle: string; eventCardType: string; eventCardDate: string; eventCardLocation: string; eventCardImage: string; eventCardLink: string; eventCardLinkText: string; }>; }; export default function Latest( { landingEvents }: LatestProps ) { // const [eventCards, setEventCards] = useState<{ type: string; title: string; date: string; location: string; image: string; link: string; }[]>([]); const carouselRef = useRef(null); const [events, setEvents] = useState([]); const eventCards = events.map((event: any) => { return { eventCardTitle: event.acf.title, eventCardType: event.acf.type, eventCardDate: event.acf.date, eventCardLocation: event.acf.address, eventCardImage: event.acf.imageUrl, eventCardLink: route('event-detail', { id: event.id }), eventCardLinkText: "for more information", }; }); async function initialize() { const data = await getNewsData('', 1, 2); setEvents([...data]); // 將獲取到的數據添加到 events 陣列中 carousel(carouselRef.current); // 在這裡可以進一步處理數據,例如更新狀態或渲染組件 } useEffect(() => { // initialize(); setEvents(landingEvents); }, []); // 空依賴陣列 -> 僅在初次掛載執行一次 return (

Latest

{eventCards .map((card: any, index: number) => ( ))}
); }