diff --git a/src/app/animals/page.tsx b/src/app/animals/page.tsx index 2b54c45..e0e4351 100644 --- a/src/app/animals/page.tsx +++ b/src/app/animals/page.tsx @@ -1,19 +1,35 @@ +// src/app/animals/page.tsx + 'use client' -import React, { useEffect, useState } from 'react' -import Navigation from '../../components/Navigation' -import { fetchAnimalRecords } from '../../services/laconicQueryService' +import { useState, useEffect } from 'react' import { MapPin } from 'lucide-react' +import { fetchAnimalRecords } from '../../services/laconicQueryService' +import Navigation from '../../components/Navigation' interface AnimalRecord { id: string - species: string + mainObject: string location: { latitude: number longitude: number } description: string imageUrl: string + species: string + // Records from Laconic Registry use `attributes` to store the content + // and have a separate creation timestamp + attributes?: { + mainObject: string + location: { + latitude: number + longitude: number + } + description: string + imageUrl: string + species: string + } + bondId?: string createTime: string } @@ -81,7 +97,7 @@ export default function AnimalsPage() { } return ( -
+
{records.map((record, index) => (
+ ANIMAL_LABELS.includes(label.description.toLowerCase()) + )?.description || 'Unknown' + + const { description } = constructDescription(labels, objects) + return { - description: constructDescription(labels, objects), + description, + mainObject, isAnimal, rawResponse: data.responses[0] } } -function constructDescription(labels: any[], objects: any[]): string { +function constructDescription(labels: any[], objects: any[]): { description: string } { const topLabels = labels .filter(label => label.score > 0.7) .map(label => label.description) @@ -74,15 +83,9 @@ function constructDescription(labels: any[], objects: any[]): string { .filter((value, index, self) => self.indexOf(value) === index) .slice(0, 3) - let description = "In this image, I can see " + // Only include "The scene includes..." part as description + let description = "The scene includes " + description += topLabels.join(", ") + "." - if (topObjects.length > 0) { - description += topObjects.join(", ") + ". " - } - - if (topLabels.length > 0) { - description += "The scene includes " + topLabels.join(", ") + "." - } - - return description + return { description } } diff --git a/src/services/laconicQueryService.ts b/src/services/laconicQueryService.ts index 4c35a62..40020d4 100644 --- a/src/services/laconicQueryService.ts +++ b/src/services/laconicQueryService.ts @@ -1,6 +1,8 @@ // src/services/laconicQueryService.ts -// + interface AnimalRecord { + id: string + mainObject: string species: string location: { latitude: number @@ -8,9 +10,9 @@ interface AnimalRecord { } description: string imageUrl: string + createTime: string } - const LACONIC_GQL_ENDPOINT = process.env.NEXT_PUBLIC_LACONIC_GQL_ENDPOINT || 'https://laconicd-sapo.laconic.com/api' const ANIMAL_RECORDS_QUERY = ` @@ -88,7 +90,8 @@ export async function fetchAnimalRecords(): Promise { longitude: location.longitude || 0 }, description: attributesMap.description || 'No description', - imageUrl: attributesMap.imageUrl || null + imageUrl: attributesMap.imageUrl || null, + createTime: record.createTime || '' } }) // Filter out records without an imageUrl