feat: sorting images by date
This commit is contained in:
@ -26,6 +26,7 @@ type CategoriesSpecificData = {
|
||||
|
||||
export type SearchImageStore = {
|
||||
images: Accessor<UserImage[]>;
|
||||
sortedImages: Accessor<Record<string, UserImage[]>>;
|
||||
|
||||
userImages: Accessor<JustTheImageWhatAreTheseNames>;
|
||||
|
||||
@ -52,6 +53,33 @@ export const SearchImageContextProvider: Component<ParentProps> = (props) => {
|
||||
return d.ImageProperties;
|
||||
});
|
||||
|
||||
const sortedImages = createMemo<ReturnType<SearchImageStore["sortedImages"]>>(
|
||||
() => {
|
||||
const d = data();
|
||||
if (d == null) {
|
||||
return {};
|
||||
}
|
||||
|
||||
// Sorted by day. But we could potentially add more in the future.
|
||||
const buckets: ReturnType<SearchImageStore["sortedImages"]> = {};
|
||||
|
||||
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<ParentProps> = (props) => {
|
||||
<SearchImageContext.Provider
|
||||
value={{
|
||||
images: imageData,
|
||||
sortedImages,
|
||||
imagesWithProperties: imagesWithProperties,
|
||||
userImages: () => data()?.UserImages ?? [],
|
||||
processingImages,
|
||||
|
Reference in New Issue
Block a user