mirror of
https://github.com/easydiffusion/easydiffusion.git
synced 2024-11-27 02:33:10 +01:00
Merge pull request #10 from caranicas/beta-react-audio
Beta react audio
This commit is contained in:
commit
9a67617cef
@ -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 () => {
|
||||
|
@ -0,0 +1,25 @@
|
||||
import React from "react";
|
||||
|
||||
import { useRef } from "react";
|
||||
import { API_URL } from "../../../api";
|
||||
|
||||
const url = `${API_URL}/ding.mp3`;
|
||||
|
||||
const AudioDing = React.forwardRef((props, ref) => (
|
||||
<audio ref={ref} style={{display:'none'}}>
|
||||
<source src={url} type="audio/mp3"/>
|
||||
</audio>
|
||||
));
|
||||
|
||||
export default AudioDing;
|
||||
|
||||
// {
|
||||
// const url = `${API_URL}/ding.mp3`;
|
||||
// const audioRef = useRef<HTMLAudioElement>(null);
|
||||
|
||||
// return (
|
||||
// <audio ref={audioRef} style={{display:'none'}}>
|
||||
// <source src={url} type="audio/mp3"/>
|
||||
// </audio>
|
||||
// );
|
||||
// }
|
@ -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());
|
||||
|
||||
|
@ -1,13 +1,14 @@
|
||||
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";
|
||||
|
||||
import GeneratedImage from "./generatedImage";
|
||||
|
||||
@ -17,6 +18,38 @@ type CompletedImagesType = {
|
||||
info: ImageRequest;
|
||||
};
|
||||
export default function DisplayPanel() {
|
||||
|
||||
const dingRef = useRef<HTMLAudioElement>(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<CompletedImagesType[]>(
|
||||
[]
|
||||
@ -61,7 +94,8 @@ export default function DisplayPanel() {
|
||||
<div className="display-panel">
|
||||
<h1>Display Panel</h1>
|
||||
<div>
|
||||
<CurrentImage />
|
||||
<AudioDing ref={dingRef}></AudioDing>
|
||||
{/* <CurrentImage /> */}
|
||||
{completedImages.map((image, index) => {
|
||||
// if(index == 0){
|
||||
// return null;
|
||||
|
@ -115,7 +115,7 @@ export const useImageCreate = create<ImageCreateState>(
|
||||
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[],
|
||||
|
Loading…
Reference in New Issue
Block a user