Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/yunn0123/react_app
Browse files Browse the repository at this point in the history
  • Loading branch information
yunn0123 committed Sep 7, 2024
2 parents 6324321 + 0c2b61b commit b271ea8
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
Empty file added src/components/css/record.css
Empty file.
56 changes: 56 additions & 0 deletions src/components/record.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React, { useEffect, useState } from 'react';
import artData from './artData.json'; // 將本地 artData.json 檔案匯入
import './css/record.css';


const ArtInfo = () => {
const [apiData, setApiData] = useState([]); // 儲存從 API 獲取的資料
const [loading, setLoading] = useState(true);

// 模擬從 API 獲取資料
useEffect(() => {
fetch('https://example.com/api/data') // 替換為真實 API 的 URL
.then(response => response.json())
.then(data => {
setApiData(data);
setLoading(false);
})
.catch(error => console.error('Error fetching data:', error));
}, []);

// 根據 art_id 找到對應的作品資訊
const getArtDetailsById = (artId) => {
return artData.find(art => art.art_id === artId);
};

if (loading) {
return <p>Loading...</p>;
}

return (
<div>
<h2>API Data and Art Information</h2>
{apiData.map((item) => {
const artDetails = getArtDetailsById(item.art_id);

return (
<div key={item.id}>
<p><strong>時間:</strong> {new Date(item.timestamp).toLocaleString()}</p>
{artDetails ? (
<div>
<p><strong>名稱:</strong> {artDetails.name}</p>
<p><strong>說明:</strong> {artDetails.description}</p>
<p><strong>地址:</strong> {artDetails.address}</p>
</div>
) : (
<p>找不到對應的藝術作品資料。</p>
)}
<hr />
</div>
);
})}
</div>
);
};

export default ArtInfo;
Binary file added src/img/poster.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b271ea8

Please sign in to comment.