diff --git a/frontend/src/components/ImageViewer.tsx b/frontend/src/components/ImageViewer.tsx index edb5144..c9cdb08 100644 --- a/frontend/src/components/ImageViewer.tsx +++ b/frontend/src/components/ImageViewer.tsx @@ -9,15 +9,26 @@ type ImageViewerProps = { ) => void; }; +// This probably shouldn't live here. +// The request should be made from rust but hey. +// We'll do that later + export const ImageViewer: Component = (props) => { // const [latestImage, setLatestImage] = createSignal(null); + let sentImage = ""; + createEffect(async () => { // Listen for PNG processing events const unlisten = listen("png-processed", async (event) => { - console.log("Received processed PNG", event); const base64Data = event.payload as string; + if (base64Data === sentImage) { + return; + } + + sentImage = base64Data; + const appWindow = getCurrentWindow(); appWindow.show(); diff --git a/frontend/src/components/image-status/ImageStatus.tsx b/frontend/src/components/image-status/ImageStatus.tsx index 9ff43f9..f49a6fc 100644 --- a/frontend/src/components/image-status/ImageStatus.tsx +++ b/frontend/src/components/image-status/ImageStatus.tsx @@ -1,4 +1,4 @@ -import { createEffect, Show, type Accessor, type Component } from "solid-js"; +import { createEffect, type Accessor, type Component } from "solid-js"; import { base, type sendImage } from "../../network"; import { useSearchImageContext } from "../../contexts/SearchImageContext"; @@ -16,6 +16,8 @@ type EventData = "in-progress" | "complete"; export const ImageStatus: Component = (props) => { const { onRefetchImages } = useSearchImageContext(); + let processing = false; + const onEvent = (e: MessageEvent) => { console.log("Processing Events: ", e.data); @@ -30,6 +32,8 @@ export const ImageStatus: Component = (props) => { Status: e.data, }); + processing = false; + return; } @@ -43,10 +47,14 @@ export const ImageStatus: Component = (props) => { return; } + if (processing) { + return; + } + + processing = true; const eventSourceUrl = `${base}/image-events/${image.ID}`; const eventSource = new EventSource(eventSourceUrl); - console.log("URL: ", eventSourceUrl); eventSource.addEventListener("data", onEvent);