fix: sending multiple images at the same time
This commit is contained in:
@ -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<ImageViewerProps> = (props) => {
|
||||
// const [latestImage, setLatestImage] = createSignal<string | null>(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();
|
||||
|
@ -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<ImageStatusProps> = (props) => {
|
||||
const { onRefetchImages } = useSearchImageContext();
|
||||
|
||||
let processing = false;
|
||||
|
||||
const onEvent = (e: MessageEvent<EventData>) => {
|
||||
console.log("Processing Events: ", e.data);
|
||||
|
||||
@ -30,6 +32,8 @@ export const ImageStatus: Component<ImageStatusProps> = (props) => {
|
||||
Status: e.data,
|
||||
});
|
||||
|
||||
processing = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -43,10 +47,14 @@ export const ImageStatus: Component<ImageStatusProps> = (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);
|
||||
|
||||
|
Reference in New Issue
Block a user