mirror of
https://github.com/easydiffusion/easydiffusion.git
synced 2025-01-27 00:29:38 +01:00
audio component and gated
This commit is contained in:
parent
458dc5b232
commit
96e43cbb65
@ -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 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
|
// 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 HEALTH_PING_INTERVAL = 5000; // 5 seconds
|
||||||
export const healthPing = async () => {
|
export const healthPing = async () => {
|
||||||
|
@ -1,11 +1,25 @@
|
|||||||
import React from "react";
|
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) => (
|
||||||
<audio controls>
|
<audio ref={ref} style={{display:'none'}}>
|
||||||
<source src="/ding.mp3" type="audio/mp3"/>
|
<source src={url} type="audio/mp3"/>
|
||||||
</audio>
|
</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
|
// TODO move this logic to the display panel
|
||||||
export default function CurrentImage() {
|
export default function CurrentImage() {
|
||||||
const [imageData, setImageData] = useState(null);
|
// const [imageData, setImageData] = useState(null);
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const { id, options } = useImageQueue((state) => state.firstInQueue());
|
const { id, options } = useImageQueue((state) => state.firstInQueue());
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState, useRef } from "react";
|
||||||
import { useImageQueue } from "../../store/imageQueueStore";
|
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 CurrentImage from "./currentImage";
|
||||||
import AudioDing from "./audioDing";
|
import AudioDing from "./audioDing";
|
||||||
@ -18,6 +18,38 @@ type CompletedImagesType = {
|
|||||||
info: ImageRequest;
|
info: ImageRequest;
|
||||||
};
|
};
|
||||||
export default function DisplayPanel() {
|
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 queryClient = useQueryClient();
|
||||||
const [completedImages, setCompletedImages] = useState<CompletedImagesType[]>(
|
const [completedImages, setCompletedImages] = useState<CompletedImagesType[]>(
|
||||||
[]
|
[]
|
||||||
@ -62,8 +94,8 @@ export default function DisplayPanel() {
|
|||||||
<div className="display-panel">
|
<div className="display-panel">
|
||||||
<h1>Display Panel</h1>
|
<h1>Display Panel</h1>
|
||||||
<div>
|
<div>
|
||||||
<AudioDing></AudioDing>
|
<AudioDing ref={dingRef}></AudioDing>
|
||||||
<CurrentImage />
|
{/* <CurrentImage /> */}
|
||||||
{completedImages.map((image, index) => {
|
{completedImages.map((image, index) => {
|
||||||
// if(index == 0){
|
// if(index == 0){
|
||||||
// return null;
|
// return null;
|
||||||
|
@ -115,7 +115,7 @@ export const useImageCreate = create<ImageCreateState>(
|
|||||||
save_to_disk_path: "null",
|
save_to_disk_path: "null",
|
||||||
use_face_correction: 'GFPGANv1.3',
|
use_face_correction: 'GFPGANv1.3',
|
||||||
use_upscale: "RealESRGAN_x4plus",
|
use_upscale: "RealESRGAN_x4plus",
|
||||||
show_only_filtered_image: false,
|
show_only_filtered_image: true,
|
||||||
} as ImageRequest,
|
} as ImageRequest,
|
||||||
|
|
||||||
tags: [] as string[],
|
tags: [] as string[],
|
||||||
|
Loading…
Reference in New Issue
Block a user