Skip to content

Commit 296fc8f

Browse files
committed
fix: handle empty data
- Show "No photos yet" on Photos page when data is empty - Updated fetch-sheet script to return an empty array instead of exiting
1 parent 04667ab commit 296fc8f

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

scripts/fetch-sheet.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ function parseTsv(filePath) {
1313
const content = fs.readFileSync(filePath, 'utf8');
1414
const lines = content.trim().split('\n');
1515
if (lines.length < 2) {
16-
console.error(`No data found in TSV file: ${filePath}`);
17-
process.exit(1);
16+
console.warn(`No data found in TSV file: ${filePath}`);
17+
return [];
1818
}
1919
const headers = lines[0].split('\t').map(h => h.trim());
2020
const data = lines.slice(1).map(line => {

src/pages/Photos.jsx

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,27 @@ const Photos = () => {
4949
<div className="pages">
5050
<Title name='Photos' />
5151
{/* Photos */}
52-
<ul className="grid grid-cols-1 md:grid-cols-2 gap-md">
53-
{data.map((item, index) => (
54-
<li key={`photos-${index}`} className="text-sm flex flex-col space-y-sm">
55-
<div onClick={() => setSelectedImage(item.Image)} className="cursor-pointer">
56-
<Image id={item.Id} path={item.Image} />
57-
</div>
58-
{item.Description && <p>{item.Description}</p>}
59-
{item.Date && <p className="italic">{formatDate(item.Date)}</p>}
60-
</li>
61-
))}
62-
</ul>
52+
{data.length === 0 && (
53+
<div className="h-full flex flex-col justify-center items-center text-center">
54+
<h2>No photos yet</h2>
55+
<p className="text-ugray">
56+
updates coming soon!<br />
57+
</p>
58+
</div>
59+
)}
60+
{data.length > 0 && (
61+
<ul className="grid grid-cols-1 md:grid-cols-2 gap-md">
62+
{data.map((item, index) => (
63+
<li key={`photos-${index}`} className="text-sm flex flex-col space-y-sm">
64+
<div onClick={() => setSelectedImage(item.Image)} className="cursor-pointer">
65+
<Image id={item.Id} path={item.Image} />
66+
</div>
67+
{item.Description && <p>{item.Description}</p>}
68+
{item.Date && <p className="italic">{formatDate(item.Date)}</p>}
69+
</li>
70+
))}
71+
</ul>
72+
)}
6373
{selectedImage && (
6474
<div className="fixed inset-0 bg-black/80 flex items-center justify-center z-50" onClick={() => setSelectedImage(null)}>
6575
<img src={selectedImage} alt="selected" className="max-h-6/10 max-w-6/10 rounded-xl" />

0 commit comments

Comments
 (0)