From 96e43cbb65b5edf5c0ef4c721839e32c1aad52a6 Mon Sep 17 00:00:00 2001 From: caranicas Date: Wed, 14 Sep 2022 17:19:40 -0400 Subject: [PATCH] audio component and gated --- ui/frontend/build_src/src/api/index.ts | 2 +- .../displayPanel/audioDing/index.tsx | 28 +++++++++--- .../displayPanel/currentImage/index.tsx | 2 +- .../src/components/displayPanel/index.tsx | 44 ++++++++++++++++--- .../build_src/src/store/imageCreateStore.ts | 2 +- 5 files changed, 62 insertions(+), 16 deletions(-) diff --git a/ui/frontend/build_src/src/api/index.ts b/ui/frontend/build_src/src/api/index.ts index 22a31161..624c03fc 100644 --- a/ui/frontend/build_src/src/api/index.ts +++ b/ui/frontend/build_src/src/api/index.ts @@ -6,7 +6,7 @@ import type { ImageRequest } from "../store/imageCreateStore"; // when we are on dev we want to specifiy 9000 as the port for the backend // when we are on prod we want be realtive to the current url -const API_URL = import.meta.env.DEV ? "http://localhost:9000" : ""; +export const API_URL = import.meta.env.DEV ? "http://localhost:9000" : ""; export const HEALTH_PING_INTERVAL = 5000; // 5 seconds export const healthPing = async () => { diff --git a/ui/frontend/build_src/src/components/displayPanel/audioDing/index.tsx b/ui/frontend/build_src/src/components/displayPanel/audioDing/index.tsx index 07d0ec5d..c6ec7edd 100644 --- a/ui/frontend/build_src/src/components/displayPanel/audioDing/index.tsx +++ b/ui/frontend/build_src/src/components/displayPanel/audioDing/index.tsx @@ -1,11 +1,25 @@ import React from "react"; +import { useRef } from "react"; +import { API_URL } from "../../../api"; -export default function AudioDing() { +const url = `${API_URL}/ding.mp3`; - return ( - - ); -} +const AudioDing = React.forwardRef((props, ref) => ( + +)); + +export default AudioDing; + +// { +// const url = `${API_URL}/ding.mp3`; +// const audioRef = useRef(null); + +// return ( +// +// ); +// } diff --git a/ui/frontend/build_src/src/components/displayPanel/currentImage/index.tsx b/ui/frontend/build_src/src/components/displayPanel/currentImage/index.tsx index d081742b..97552a99 100644 --- a/ui/frontend/build_src/src/components/displayPanel/currentImage/index.tsx +++ b/ui/frontend/build_src/src/components/displayPanel/currentImage/index.tsx @@ -8,7 +8,7 @@ import GeneratedImage from "../generatedImage"; // TODO move this logic to the display panel export default function CurrentImage() { - const [imageData, setImageData] = useState(null); + // const [imageData, setImageData] = useState(null); // @ts-ignore const { id, options } = useImageQueue((state) => state.firstInQueue()); diff --git a/ui/frontend/build_src/src/components/displayPanel/index.tsx b/ui/frontend/build_src/src/components/displayPanel/index.tsx index 4481c13f..778117a5 100644 --- a/ui/frontend/build_src/src/components/displayPanel/index.tsx +++ b/ui/frontend/build_src/src/components/displayPanel/index.tsx @@ -1,11 +1,11 @@ -import React, { useEffect, useState } from "react"; +import React, { useEffect, useState, useRef } from "react"; import { useImageQueue } from "../../store/imageQueueStore"; -import { ImageRequest } from "../../store/imageCreateStore"; +import { ImageRequest, useImageCreate } from "../../store/imageCreateStore"; -import { useQueryClient } from "@tanstack/react-query"; +import {useQuery, useQueryClient } from "@tanstack/react-query"; -import { MakeImageKey } from "../../api"; +import {doMakeImage, MakeImageKey } from "../../api"; import CurrentImage from "./currentImage"; import AudioDing from "./audioDing"; @@ -18,6 +18,38 @@ type CompletedImagesType = { info: ImageRequest; }; export default function DisplayPanel() { + + const dingRef = useRef(null); + const isSoundEnabled = useImageCreate((state) => state.isSoundEnabled()); + + /* FETCHING */ + // @ts-ignore + const { id, options } = useImageQueue((state) => state.firstInQueue()); + const removeFirstInQueue = useImageQueue((state) => state.removeFirstInQueue); + const { status, data } = useQuery( + [MakeImageKey, id], + () => doMakeImage(options), + { + enabled: void 0 !== id, + } + ); + + useEffect(() => { + // query is done + if (status === "success") { + // check to make sure that the image was created + if (data.status === "succeeded") { + if(isSoundEnabled) { + dingRef.current?.play(); + } + removeFirstInQueue(); + } + } + }, [status, data, removeFirstInQueue, dingRef, isSoundEnabled]); + + + /* COMPLETED IMAGES */ + const queryClient = useQueryClient(); const [completedImages, setCompletedImages] = useState( [] @@ -62,8 +94,8 @@ export default function DisplayPanel() {

Display Panel

- - + + {/* */} {completedImages.map((image, index) => { // if(index == 0){ // return null; diff --git a/ui/frontend/build_src/src/store/imageCreateStore.ts b/ui/frontend/build_src/src/store/imageCreateStore.ts index 34f9d814..c0864574 100644 --- a/ui/frontend/build_src/src/store/imageCreateStore.ts +++ b/ui/frontend/build_src/src/store/imageCreateStore.ts @@ -115,7 +115,7 @@ export const useImageCreate = create( save_to_disk_path: "null", use_face_correction: 'GFPGANv1.3', use_upscale: "RealESRGAN_x4plus", - show_only_filtered_image: false, + show_only_filtered_image: true, } as ImageRequest, tags: [] as string[],