From 4b9d3e7d55a38882eb960eda00fb4a6f8c78c162 Mon Sep 17 00:00:00 2001 From: Felipe Cardoso Date: Thu, 23 Jan 2025 13:10:58 +0100 Subject: [PATCH] Refactor samples gallery Signed-off-by: Felipe Cardoso --- backend/app/api/routes/samples.py | 4 ++-- backend/app/services/sample_manager.py | 4 ++-- frontend/src/components/SamplesGallery.tsx | 10 +++++----- frontend/src/contexts/SamplesContext.tsx | 4 +++- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/backend/app/api/routes/samples.py b/backend/app/api/routes/samples.py index 9857791..b6b1288 100644 --- a/backend/app/api/routes/samples.py +++ b/backend/app/api/routes/samples.py @@ -10,7 +10,7 @@ router = APIRouter() @router.get("/list", response_model=List[Sample]) async def list_samples( request: Request, - limit: int = Query(20, ge=1, le=1000), + limit: int = Query(200, ge=1, le=1000), offset: int = Query(0, ge=0) ): """ @@ -25,7 +25,7 @@ async def list_samples( @router.get("/latest", response_model=List[Sample]) async def get_latest_samples( request: Request, - count: int = Query(5, ge=1, le=20) + count: int = Query(20, ge=1, le=100) ): """ Get the most recent sample images diff --git a/backend/app/services/sample_manager.py b/backend/app/services/sample_manager.py index 28c9fa7..2c98abd 100644 --- a/backend/app/services/sample_manager.py +++ b/backend/app/services/sample_manager.py @@ -191,7 +191,7 @@ class SampleManager: # Wait a bit before retrying on error await asyncio.sleep(5) - async def list_samples(self, limit: int = 20, offset: int = 0) -> List[Sample]: + async def list_samples(self, limit: int = 200, offset: int = 0) -> List[Sample]: """List sample images with pagination""" logger.info(f"Total samples: {len(self.samples)}") @@ -204,7 +204,7 @@ class SampleManager: return sorted_samples[offset:offset + limit] - async def get_latest_samples(self, count: int = 5) -> List[Sample]: + async def get_latest_samples(self, count: int = 20) -> List[Sample]: """Get most recent samples""" return await self.list_samples(limit=count, offset=0) diff --git a/frontend/src/components/SamplesGallery.tsx b/frontend/src/components/SamplesGallery.tsx index 47e4f66..0930086 100644 --- a/frontend/src/components/SamplesGallery.tsx +++ b/frontend/src/components/SamplesGallery.tsx @@ -3,15 +3,15 @@ import {useSamples} from '@/contexts/SamplesContext' import Image from 'next/image' export function SamplesGallery() { - const {samples, isLoading, error, refreshSamples} = useSamples() + const {latestSamples, isLoading, error, refreshSamples} = useSamples() if (isLoading) return
Loading samples...
if (error) return
Error loading samples: {error.message}
- if (samples.length === 0) return
No samples available
+ if (latestSamples.length === 0) return
No samples available
return ( -
- {samples.map((sample) => ( +
+ {latestSamples.map((sample) => (
-

{sample.filename}

+

{sample.url.split('__')[1]}

))}
diff --git a/frontend/src/contexts/SamplesContext.tsx b/frontend/src/contexts/SamplesContext.tsx index 0269177..a041748 100644 --- a/frontend/src/contexts/SamplesContext.tsx +++ b/frontend/src/contexts/SamplesContext.tsx @@ -4,6 +4,7 @@ import type {Sample} from '@/types/api' interface SamplesContextType { samples: Sample[] + latestSamples: Sample[] isLoading: boolean error: Error | null refreshSamples: () => Promise @@ -37,7 +38,8 @@ export function SamplesProvider({children}: { children: React.ReactNode }) { }, []) return ( - + {children} )