diff --git a/frontend/src/components/image/index.tsx b/frontend/src/components/image/index.tsx index 50b6458..df96dcb 100644 --- a/frontend/src/components/image/index.tsx +++ b/frontend/src/components/image/index.tsx @@ -6,10 +6,12 @@ import { Dialog } from "@kobalte/core"; type ImageComponentProps = { ID: string; onDelete: (id: string) => void; -} + onRefresh: (id: string) => void; +}; export const ImageComponent: Component = (props) => { const [isOpen, setIsOpen] = createSignal(false); + const [isRefreshOpen, setIsRefreshOpen] = createSignal(false); return ( <> @@ -27,53 +29,12 @@ export const ImageComponent: Component = (props) => { > × - - - - - - - - Confirm Delete - - - Are you sure you want to delete this image? - -
- - - - -
-
-
-
- - ); -}; - -export const ImageComponentFullHeight: Component = (props) => { - const [isOpen, setIsOpen] = createSignal(false); - - return ( - <> -
- - -
@@ -93,7 +54,131 @@ export const ImageComponentFullHeight: Component = (props) Cancel - + + + + + + + + + + + Confirm Refresh + + + Are you sure you want to refresh this image? + +
+ + + + +
+
+
+
+ + ); +}; + +export const ImageComponentFullHeight: Component = ( + props, +) => { + const [isOpen, setIsOpen] = createSignal(false); + const [isRefreshOpen, setIsRefreshOpen] = createSignal(false); + + return ( + <> +
+ + + + + +
+ + + + + + + Confirm Delete + + + Are you sure you want to delete this image? + +
+ + + + +
+
+
+
+ + + + + + + Confirm Refresh + + + Are you sure you want to refresh this image? + +
+ + + +
diff --git a/frontend/src/contexts/SearchImageContext.tsx b/frontend/src/contexts/SearchImageContext.tsx index e6d87ac..6835eac 100644 --- a/frontend/src/contexts/SearchImageContext.tsx +++ b/frontend/src/contexts/SearchImageContext.tsx @@ -7,7 +7,7 @@ import { createResource, useContext, } from "solid-js"; -import { deleteImage, deleteImageFromStack, getUserImages, JustTheImageWhatAreTheseNames } from "../network"; +import { deleteImage, deleteImageFromStack, getUserImages, JustTheImageWhatAreTheseNames, reprocessImage } from "../network"; export type SearchImageStore = { imagesByDate: Accessor< @@ -25,6 +25,7 @@ export type SearchImageStore = { onRefetchImages: () => void; onDeleteImage: (imageID: string) => void; onDeleteImageFromStack: (stackID: string, imageID: string) => void; + onRefreshImage: (imageID: string) => void; }; const SearchImageContext = createContext(); @@ -75,6 +76,9 @@ export const SearchImageContextProvider: Component = (props) => { }, onDeleteImageFromStack: (stackID: string, imageID: string) => { deleteImageFromStack(stackID, imageID).then(refetch); + }, + onRefreshImage: (imageID: string) => { + reprocessImage(imageID).then(refetch) } }} > diff --git a/frontend/src/network/index.ts b/frontend/src/network/index.ts index 715c109..6899d20 100644 --- a/frontend/src/network/index.ts +++ b/frontend/src/network/index.ts @@ -18,7 +18,7 @@ import { type BaseRequestParams = Partial<{ path: string; body: RequestInit["body"]; - method: "GET" | "POST" | "DELETE"; + method: "GET" | "POST" | "DELETE" | "PATCH"; }>; // export const base = "https://haystack.johncosta.tech"; @@ -296,3 +296,19 @@ export const createList = async ( throw new ReachedListLimit(); } }; + +export const reprocessImage = async ( + id: string +): Promise => { + const request = getBaseAuthorizedRequest({ + path: `images/${id}`, + method: "PATCH" + }); + + request.headers.set("Content-Type", "application/json"); + + const res = await fetch(request); + if (!res.ok && res.status == 429) { + throw new ReachedListLimit(); + } +} diff --git a/frontend/src/pages/all-images/index.tsx b/frontend/src/pages/all-images/index.tsx index c588907..d9a5e38 100644 --- a/frontend/src/pages/all-images/index.tsx +++ b/frontend/src/pages/all-images/index.tsx @@ -3,7 +3,6 @@ import { Component, For } from "solid-js"; import { createVirtualizer } from "@tanstack/solid-virtual"; import { ImageComponent } from "@components/image"; import { chunkRows } from "./chunk"; -import { deleteImage } from "@network/index"; type ImageOrDate = | { type: "image"; ID: string[] } @@ -12,7 +11,8 @@ type ImageOrDate = export const AllImages: Component = () => { let scrollRef: HTMLDivElement | undefined; - const { imagesByDate, onDeleteImage } = useSearchImageContext(); + const { imagesByDate, onDeleteImage, onRefreshImage } = + useSearchImageContext(); const items = () => { const items: Array = []; @@ -48,7 +48,15 @@ export const AllImages: Component = () => { const item = items()[i.index]; if (item.type === "image") { return ( - {(id) => } + + {(id) => ( + + )} + ); } else { return ( diff --git a/frontend/src/pages/front/recent.tsx b/frontend/src/pages/front/recent.tsx index 4925179..7ef5313 100644 --- a/frontend/src/pages/front/recent.tsx +++ b/frontend/src/pages/front/recent.tsx @@ -1,18 +1,19 @@ import { Component, For } from "solid-js"; import { ImageComponent } from "@components/image"; import { useSearchImageContext } from "@contexts/SearchImageContext"; -import { deleteImage } from "@network/index"; const NUMBER_OF_MAX_RECENT_IMAGES = 10; export const Recent: Component = () => { - const { userImages, onDeleteImage } = useSearchImageContext(); + const { userImages, onDeleteImage, onRefreshImage } = + useSearchImageContext(); const latestImages = () => userImages() .sort( (a, b) => - new Date(b.CreatedAt!).getTime() - new Date(a.CreatedAt!).getTime(), + new Date(b.CreatedAt!).getTime() - + new Date(a.CreatedAt!).getTime(), ) .slice(0, NUMBER_OF_MAX_RECENT_IMAGES); @@ -21,7 +22,13 @@ export const Recent: Component = () => {

Recent Screenshots

- {(image) => } + {(image) => ( + + )}
diff --git a/frontend/src/pages/image/index.tsx b/frontend/src/pages/image/index.tsx index 96b3747..bd6cf83 100644 --- a/frontend/src/pages/image/index.tsx +++ b/frontend/src/pages/image/index.tsx @@ -9,17 +9,22 @@ export const ImagePage: Component = () => { const { imageId } = useParams<{ imageId: string }>(); const nav = useNavigate(); - const { userImages, lists, onDeleteImage } = useSearchImageContext(); + const { userImages, lists, onDeleteImage, onRefreshImage } = + useSearchImageContext(); const image = () => userImages().find((i) => i.ImageID === imageId); return (
- { - onDeleteImage(id); - nav("/"); - }} /> + { + onDeleteImage(id); + nav("/"); + }} + onRefresh={onRefreshImage} + />

Description

@@ -27,7 +32,11 @@ export const ImagePage: Component = () => { {(imageList) => ( l.ID === imageList.ListID)!} + list={ + lists().find( + (l) => l.ID === imageList.ListID, + )! + } /> )} diff --git a/frontend/src/pages/search/index.tsx b/frontend/src/pages/search/index.tsx index 3c04d60..4358cbb 100644 --- a/frontend/src/pages/search/index.tsx +++ b/frontend/src/pages/search/index.tsx @@ -9,7 +9,7 @@ import { useSearchImageContext } from "@contexts/SearchImageContext"; export const SearchPage: Component = () => { const fuse = useSearch(); - const { onDeleteImage } = useSearchImageContext(); + const { onDeleteImage, onRefreshImage } = useSearchImageContext(); const [searchItems, setSearchItems] = createSignal([]); @@ -41,7 +41,13 @@ export const SearchPage: Component = () => { - {(item) => } + {(item) => ( + + )} No result found