From 5a1f3bb75b80b5fb6adc6527c4cc95526326f2a6 Mon Sep 17 00:00:00 2001 From: John Costa Date: Fri, 18 Jul 2025 14:26:23 +0100 Subject: [PATCH] feat: recent displayed on front page --- frontend/src/Image.tsx | 8 +------ frontend/src/Recent.tsx | 22 ++++++++++++++++++++ frontend/src/Search.tsx | 3 +++ frontend/src/components/image/index.tsx | 7 ++++++- frontend/src/contexts/SearchImageContext.tsx | 9 +++++++- frontend/src/network/index.ts | 4 ++++ 6 files changed, 44 insertions(+), 9 deletions(-) create mode 100644 frontend/src/Recent.tsx diff --git a/frontend/src/Image.tsx b/frontend/src/Image.tsx index 5ee0409..6a98340 100644 --- a/frontend/src/Image.tsx +++ b/frontend/src/Image.tsx @@ -1,9 +1,8 @@ -import { A, useParams } from "@solidjs/router"; +import { useParams } from "@solidjs/router"; import { For, Show, type Component } from "solid-js"; import { base, type UserImage } from "./network"; import { useSearchImageContext } from "./contexts/SearchImageContext"; import { SearchCard } from "./components/search-card/SearchCard"; -import { IconArrowLeft } from "@tabler/icons-solidjs"; export const Image: Component = () => { const { imageId } = useParams<{ imageId: string }>(); @@ -15,11 +14,6 @@ export const Image: Component = () => { return (
- users
diff --git a/frontend/src/Recent.tsx b/frontend/src/Recent.tsx new file mode 100644 index 0000000..b9daacb --- /dev/null +++ b/frontend/src/Recent.tsx @@ -0,0 +1,22 @@ +import { Component, For } from "solid-js"; +import { useSearchImageContext } from "./contexts/SearchImageContext"; +import { Image } from "./components/image"; + +export const Recent: Component = () => { + const { userImages } = useSearchImageContext(); + + const latestImages = () => + userImages() + .sort( + (a, b) => + new Date(b.CreatedAt!).getTime() - new Date(a.CreatedAt!).getTime(), + ) + .slice(0, 10); + + return ( +
+

Recent

+ {(image) => } +
+ ); +}; diff --git a/frontend/src/Search.tsx b/frontend/src/Search.tsx index d958ec7..dad74c7 100644 --- a/frontend/src/Search.tsx +++ b/frontend/src/Search.tsx @@ -19,6 +19,7 @@ import { A } from "@solidjs/router"; import { useSetEntity } from "./WithEntityDialog"; import { ProcessingImages } from "./notifications/ProcessingImages"; import { Categories } from "./front"; +import { Recent } from "./Recent"; export const Search = () => { const [searchResults, setSearchResults] = createSignal([]); @@ -103,6 +104,8 @@ export const Search = () => { + +
diff --git a/frontend/src/components/image/index.tsx b/frontend/src/components/image/index.tsx index 5c30065..9b9f8ab 100644 --- a/frontend/src/components/image/index.tsx +++ b/frontend/src/components/image/index.tsx @@ -1,6 +1,11 @@ import { Component } from "solid-js"; import { base } from "../../network"; +import { A } from "@solidjs/router"; export const Image: Component<{ ID: string }> = (props) => { - return ; + return ( + + + + ); }; diff --git a/frontend/src/contexts/SearchImageContext.tsx b/frontend/src/contexts/SearchImageContext.tsx index f3ba757..26469d8 100644 --- a/frontend/src/contexts/SearchImageContext.tsx +++ b/frontend/src/contexts/SearchImageContext.tsx @@ -7,7 +7,11 @@ import { createResource, useContext, } from "solid-js"; -import { CategoryUnion, getUserImages } from "../network"; +import { + CategoryUnion, + getUserImages, + JustTheImageWhatAreTheseNames, +} from "../network"; import { groupPropertiesWithImage } from "../utils/groupPropertiesWithImage"; export type ImageWithRawData = Awaited< @@ -28,6 +32,8 @@ type CategoriesSpecificData = { export type SearchImageStore = { images: Accessor; + userImages: Accessor; + imagesWithProperties: Accessor>; processingImages: Accessor< Awaited>["ProcessingImages"] | undefined @@ -122,6 +128,7 @@ export const SearchImageContextProvider: Component = (props) => { value={{ images: imageData, imagesWithProperties: imagesWithProperties, + userImages: () => data()?.UserImages ?? [], processingImages, onRefetchImages: refetch, categories, diff --git a/frontend/src/network/index.ts b/frontend/src/network/index.ts index d04f794..7189b23 100644 --- a/frontend/src/network/index.ts +++ b/frontend/src/network/index.ts @@ -192,6 +192,10 @@ const imageRequestValidator = strictObject({ ProcessingImages: array(userProcessingImageValidator), }); +export type JustTheImageWhatAreTheseNames = InferOutput< + typeof userImageValidator +>[]; + export const getUserImages = async (): Promise< InferOutput > => {