diff --git a/frontend/src/app/samples/page.tsx b/frontend/src/app/samples/page.tsx new file mode 100644 index 0000000..5d87e06 --- /dev/null +++ b/frontend/src/app/samples/page.tsx @@ -0,0 +1,96 @@ +// src/app/samples/page.tsx +"use client" + +import {useSamples} from '@/contexts/SamplesContext' +import Image from 'next/image' +import {useMemo} from 'react' + +interface ParsedSample { + filename: string + timestamp: number + batch: number + index: number + url: string + created_at: string +} + +export default function SamplesPage() { + const {samples, isLoading, error} = useSamples() + + const groupedSamples = useMemo(() => { + if (!samples?.length) return new Map() + + const parsed: ParsedSample[] = samples.map(sample => { + console.debug('sample', sample) + const [timestamp, info] = sample.filename.split('__') + const [batch, index] = info.split('_') + return { + ...sample, + timestamp: parseInt(timestamp), + batch: parseInt(batch), + index: parseInt(index.replace('.jpg', '')), + } + }) + + // Group by batch + const groups = parsed.reduce((acc, sample) => { + const group = acc.get(sample.batch) || [] + group.push(sample) + acc.set(sample.batch, group) + return acc + }, new Map()) + + // Sort within each group + for (const [batch, items] of groups) { + groups.set(batch, items.sort((a, b) => b.index - a.index)) + } + + // return new Map([...groups].sort((a, b) => b[0] - a[0])) + return new Map([...groups]) + }, [samples]) + + if (isLoading) return
Loading samples...
+ if (error) return
Error: {error.message}
+ + return ( +
+

Samples Gallery

+ + {Array.from(groupedSamples).map(([batch, items]) => ( +
+

+ Step {batch} +

+
+
+ {items.sort((a: any, b: any) => a.index - b.index).map((sample: any) => ( +
+ {`Sample +
+
+ {new Date(sample.created_at).toLocaleString()} +
+ + Sample {sample.index} + +
+
+ ))} +
+
+
+ ))} +
+ ) +} \ No newline at end of file