From d48108429b7024c3c13978b98905a56b59cd9954 Mon Sep 17 00:00:00 2001 From: zramsay Date: Sat, 11 Jan 2025 18:21:38 -0500 Subject: [PATCH] reverse image display and use env var to omit certain records --- src/app/animals/page.tsx | 143 ++++++++++++++++++++++----------------- 1 file changed, 81 insertions(+), 62 deletions(-) diff --git a/src/app/animals/page.tsx b/src/app/animals/page.tsx index fdce8bd..2b54c45 100644 --- a/src/app/animals/page.tsx +++ b/src/app/animals/page.tsx @@ -6,6 +6,7 @@ import { fetchAnimalRecords } from '../../services/laconicQueryService' import { MapPin } from 'lucide-react' interface AnimalRecord { + id: string species: string location: { latitude: number @@ -13,8 +14,13 @@ interface AnimalRecord { } description: string imageUrl: string + createTime: string } +const hiddenIndices = (process.env.NEXT_PUBLIC_HIDDEN_INDICES?.split(',') || []) + .map(num => parseInt(num)) + .filter(num => !isNaN(num)) + export default function AnimalsPage() { const [records, setRecords] = useState([]) const [loading, setLoading] = useState(true) @@ -29,7 +35,19 @@ export default function AnimalsPage() { setLoading(true) setError(null) const data = await fetchAnimalRecords() - setRecords(data) + + // Sort by creation time, oldest first + const sortedRecords = [...data].sort((a, b) => + new Date(a.createTime).getTime() - new Date(b.createTime).getTime() + ) + + // Filter out records by their chronological index (1-based) + const filteredRecords = sortedRecords.filter((_, index) => + !hiddenIndices.includes(index + 1) + ) + + // Reverse to show newest first + setRecords(filteredRecords.reverse()) } catch (error) { setError('Failed to load animal records') } finally { @@ -37,80 +55,81 @@ export default function AnimalsPage() { } } + const renderContent = () => { + if (loading) { + return ( +
+ Loading animal records... +
+ ) + } + + if (error) { + return ( +
+ {error} +
+ ) + } + + if (records.length === 0) { + return ( +
+ No animal records found yet. Be the first to contribute! +
+ ) + } + + return ( +
+ {records.map((record, index) => ( +
+
+ {`${record.species} +
+ +

+ {record.species} +

+ +
+ + + {record.location.latitude}°, {record.location.longitude}° + +
+ +

+ {record.description} +

+
+ ))} +
+ ) + } + return (
- {/* Header */}

Animal Registry

- Discover wildlife sightings from around the world + Discover wildlife sightings from our community

- {/* Loading State */} - {loading && ( -
- Loading animal records... -
- )} - - {/* Error State */} - {error && ( -
- {error} -
- )} - - {/* Records Grid */} - {!loading && !error && ( -
- {records.map((record, index) => ( -
- {/* Image */} -
- {`${record.species} -
- - {/* Species */} -

- {record.species} -

- - {/* Location */} -
- - - {record.location.latitude}°, {record.location.longitude}° - -
- - {/* Description */} -

- {record.description} -

-
- ))} -
- )} - - {/* Empty State */} - {!loading && !error && records.length === 0 && ( -
- No animal records found yet. Be the first to contribute! -
- )} + {renderContent()}
)