-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a320d21
commit 5a398b0
Showing
3 changed files
with
40 additions
and
45 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,43 @@ | ||
// app/page.tsx (or any page you'd like to use) | ||
'use client' | ||
import { useEffect, useState } from 'react'; | ||
import useSWR from 'swr'; | ||
import Card from '../../components/Card'; | ||
import { convertISOToTime } from '@/utils/dateTimeConverter'; | ||
import { convertISOToDate } from '@/utils/dateTimeConverter'; | ||
|
||
import { convertISOToTime, convertISOToDate } from '@/utils/dateTimeConverter'; | ||
|
||
type ImageData = { | ||
_id: string; | ||
buffer: string; // Base64-encoded string | ||
buffer: string; | ||
submittedAt: string; | ||
weight: string; //weight -- | ||
face: string; // 1 if happy face, 0 if unhappy face | ||
weight: string; | ||
face: string; | ||
}; | ||
|
||
|
||
const fetcher = (url: string) => fetch(url).then(res => res.json()); | ||
|
||
const ImageGallery = () => { | ||
const [images, setImages] = useState<ImageData[]>([]); | ||
const [loading, setLoading] = useState(true); | ||
|
||
useEffect(() => { | ||
const fetchImages = async () => { | ||
try { | ||
const response = await fetch('/api/get-images'); | ||
const data = await response.json(); | ||
setImages(data); | ||
} catch (error) { | ||
console.error('Error fetching images:', error); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
fetchImages(); | ||
}, []); | ||
const { data: images, error } = useSWR<ImageData[]>('/api/get-images', fetcher, { | ||
refreshInterval: 5000, // Fetch data every 5 seconds | ||
}); | ||
|
||
if (loading) { | ||
return <p className="text-black">Loading images...</p>; | ||
} | ||
if (error) return <p className="text-black">Failed to load images.</p>; | ||
if (!images) return <p className="text-black">Loading images...</p>; | ||
|
||
return ( | ||
<div className='min-h-screen bg-gray-100 p-4'> | ||
<h1 className="text-black">Image Gallery</h1> | ||
<ul style={{ listStyleType: 'none', padding: 0 }}> | ||
{/* {images.map((image) => ( | ||
<li key={image._id} style={{ marginBottom: '20px' }}> | ||
<img | ||
src={`data:image/png;base64,${image.buffer}`} | ||
alt="Submitted" | ||
style={{ width: '200px', height: '200px', objectFit: 'cover' }} | ||
/> | ||
<p>Submitted at: {new Date(image.submittedAt).toLocaleString()}</p> | ||
</li> | ||
))} */} | ||
{images.map((image) => ( | ||
<Card | ||
key={image._id} | ||
image={image} | ||
waga={image.weight} | ||
godzina={convertISOToTime(image.submittedAt)} | ||
data={convertISOToDate(image.submittedAt)} | ||
face={'1'} | ||
/> | ||
face={image.face} | ||
/> | ||
))} | ||
</ul> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ImageGallery; | ||
export default ImageGallery; |