From d5594c6e32ccd87ab367fb00622e0b458146fd91 Mon Sep 17 00:00:00 2001 From: John Costa Date: Mon, 21 Jul 2025 16:12:33 +0100 Subject: [PATCH] feat: sorting images by date --- frontend/src/contexts/SearchImageContext.tsx | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/frontend/src/contexts/SearchImageContext.tsx b/frontend/src/contexts/SearchImageContext.tsx index 193a065..380cfce 100644 --- a/frontend/src/contexts/SearchImageContext.tsx +++ b/frontend/src/contexts/SearchImageContext.tsx @@ -26,6 +26,7 @@ type CategoriesSpecificData = { export type SearchImageStore = { images: Accessor; + sortedImages: Accessor>; userImages: Accessor; @@ -52,6 +53,33 @@ export const SearchImageContextProvider: Component = (props) => { return d.ImageProperties; }); + const sortedImages = createMemo>( + () => { + const d = data(); + if (d == null) { + return {}; + } + + // Sorted by day. But we could potentially add more in the future. + const buckets: ReturnType = {}; + + for (const image of d.ImageProperties) { + if (image.data.CreatedAt == null) { + continue; + } + + const date = new Date(image.data.CreatedAt).toDateString(); + if (!(date in buckets)) { + buckets[date] = []; + } + + buckets[date].push(image); + } + + return buckets; + }, + ); + const processingImages = () => data()?.ProcessingImages ?? []; const imagesWithProperties = createMemo< @@ -88,6 +116,7 @@ export const SearchImageContextProvider: Component = (props) => { data()?.UserImages ?? [], processingImages,