fix: sending multiple images at the same time
This commit is contained in:
@ -9,15 +9,26 @@ type ImageViewerProps = {
|
|||||||
) => void;
|
) => 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) => {
|
export const ImageViewer: Component<ImageViewerProps> = (props) => {
|
||||||
// const [latestImage, setLatestImage] = createSignal<string | null>(null);
|
// const [latestImage, setLatestImage] = createSignal<string | null>(null);
|
||||||
|
|
||||||
|
let sentImage = "";
|
||||||
|
|
||||||
createEffect(async () => {
|
createEffect(async () => {
|
||||||
// Listen for PNG processing events
|
// Listen for PNG processing events
|
||||||
const unlisten = listen("png-processed", async (event) => {
|
const unlisten = listen("png-processed", async (event) => {
|
||||||
console.log("Received processed PNG", event);
|
|
||||||
const base64Data = event.payload as string;
|
const base64Data = event.payload as string;
|
||||||
|
|
||||||
|
if (base64Data === sentImage) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sentImage = base64Data;
|
||||||
|
|
||||||
const appWindow = getCurrentWindow();
|
const appWindow = getCurrentWindow();
|
||||||
|
|
||||||
appWindow.show();
|
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 { base, type sendImage } from "../../network";
|
||||||
import { useSearchImageContext } from "../../contexts/SearchImageContext";
|
import { useSearchImageContext } from "../../contexts/SearchImageContext";
|
||||||
|
|
||||||
@ -16,6 +16,8 @@ type EventData = "in-progress" | "complete";
|
|||||||
export const ImageStatus: Component<ImageStatusProps> = (props) => {
|
export const ImageStatus: Component<ImageStatusProps> = (props) => {
|
||||||
const { onRefetchImages } = useSearchImageContext();
|
const { onRefetchImages } = useSearchImageContext();
|
||||||
|
|
||||||
|
let processing = false;
|
||||||
|
|
||||||
const onEvent = (e: MessageEvent<EventData>) => {
|
const onEvent = (e: MessageEvent<EventData>) => {
|
||||||
console.log("Processing Events: ", e.data);
|
console.log("Processing Events: ", e.data);
|
||||||
|
|
||||||
@ -30,6 +32,8 @@ export const ImageStatus: Component<ImageStatusProps> = (props) => {
|
|||||||
Status: e.data,
|
Status: e.data,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
processing = false;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,10 +47,14 @@ export const ImageStatus: Component<ImageStatusProps> = (props) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (processing) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
processing = true;
|
||||||
const eventSourceUrl = `${base}/image-events/${image.ID}`;
|
const eventSourceUrl = `${base}/image-events/${image.ID}`;
|
||||||
|
|
||||||
const eventSource = new EventSource(eventSourceUrl);
|
const eventSource = new EventSource(eventSourceUrl);
|
||||||
console.log("URL: ", eventSourceUrl);
|
|
||||||
|
|
||||||
eventSource.addEventListener("data", onEvent);
|
eventSource.addEventListener("data", onEvent);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user