added audio ding

This commit is contained in:
caranicas 2022-09-28 12:54:15 -04:00
parent f58c16ab03
commit 1b439c15f6
6 changed files with 51 additions and 43 deletions

View File

@ -79,9 +79,5 @@ export const doMakeImage = async (reqBody: ImageRequest) => {
}, },
body: JSON.stringify(reqBody), body: JSON.stringify(reqBody),
}); });
console.log('doMakeImage= GOT RESPONSE', res);
// const data = await res.json();
// return data;
return res; return res;
}; };

View File

@ -13,3 +13,4 @@ const AudioDing = React.forwardRef((props, ref) => (
AudioDing.displayName = "AudioDing"; AudioDing.displayName = "AudioDing";
export default AudioDing; export default AudioDing;

View File

@ -6,8 +6,6 @@ import ModifierTag from "../../../../atoms/modifierTag";
export default function ActiveTags() { export default function ActiveTags() {
const selectedtags = useImageCreate((state) => state.selectedTags()); const selectedtags = useImageCreate((state) => state.selectedTags());
console.log("ActiveTags", selectedtags);
return ( return (
<div className="selected-tags"> <div className="selected-tags">
<p>Active Tags</p> <p>Active Tags</p>

View File

@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/naming-convention */ /* eslint-disable @typescript-eslint/naming-convention */
import React, { useEffect } from "react"; import React, { useEffect, useRef } from "react";
import { useImageCreate, ImageRequest } from "../../../../../stores/imageCreateStore"; import { useImageCreate, ImageRequest } from "../../../../../stores/imageCreateStore";
import { useImageQueue } from "../../../../../stores/imageQueueStore"; import { useImageQueue } from "../../../../../stores/imageQueueStore";
@ -25,6 +25,8 @@ import AudioDing from "../../../../molecules/audioDing";
export default function MakeButton() { export default function MakeButton() {
const { t } = useTranslation(); const { t } = useTranslation();
const dingRef = useRef<HTMLAudioElement>(null);
const parallelCount = useImageCreate((state) => state.parallelCount); const parallelCount = useImageCreate((state) => state.parallelCount);
const builtRequest = useImageCreate((state) => state.builtRequest); const builtRequest = useImageCreate((state) => state.builtRequest);
const isRandomSeed = useImageCreate((state) => state.isRandomSeed()); const isRandomSeed = useImageCreate((state) => state.isRandomSeed());
@ -100,18 +102,18 @@ export default function MakeButton() {
} }
const parseRequest = async (id: string, reader: ReadableStreamDefaultReader<Uint8Array>) => { const parseRequest = async (id: string, reader: ReadableStreamDefaultReader<Uint8Array>) => {
console.log('parseRequest');
const decoder = new TextDecoder(); const decoder = new TextDecoder();
let finalJSON = ''; let finalJSON = '';
console.log('id', id); //console.log('id', id);
while (true) { while (true) {
const { done, value } = await reader.read(); const { done, value } = await reader.read();
const jsonStr = decoder.decode(value); const jsonStr = decoder.decode(value);
if (done) { if (done) {
removeFirstInQueue(); removeFirstInQueue();
setStatus(FetchingStates.COMPLETE); setStatus(FetchingStates.COMPLETE);
hackJson(finalJSON) hackJson(finalJSON);
void dingRef.current?.play();
break; break;
} }
@ -262,14 +264,17 @@ export default function MakeButton() {
}, [hasQueue, status, id, options, startStream]); }, [hasQueue, status, id, options, startStream]);
return ( return (
<button <>
className={MakeButtonStyle} <button
onClick={() => { className={MakeButtonStyle}
void makeImageQueue(); onClick={() => {
}} void makeImageQueue();
disabled={hasQueue} }}
> disabled={hasQueue}
{t("home.make-img-btn")} >
</button> {t("home.make-img-btn")}
</button>
<AudioDing ref={dingRef}></AudioDing>
</>
); );
} }

View File

@ -1,8 +1,10 @@
import React, { useEffect, useState } from "react"; import React, { useEffect, useState, useRef } from "react";
import { useQuery } from "@tanstack/react-query"; import { useQuery } from "@tanstack/react-query";
import { healthPing, HEALTH_PING_INTERVAL } from "../../../../api"; import { healthPing, HEALTH_PING_INTERVAL } from "../../../../api";
import AudioDing from "../../../molecules/audioDing";
import { import {
StartingStatus, StartingStatus,
ErrorStatus, ErrorStatus,
@ -17,6 +19,8 @@ export default function StatusDisplay({ className }: { className?: string }) {
const [statusMessage, setStatusMessage] = useState(startingMessage); const [statusMessage, setStatusMessage] = useState(startingMessage);
const [statusClass, setStatusClass] = useState(StartingStatus); const [statusClass, setStatusClass] = useState(StartingStatus);
const dingRef = useRef<HTMLAudioElement>(null);
// but this will be moved to the status display when it is created // but this will be moved to the status display when it is created
const { status, data } = useQuery(["health"], healthPing, { const { status, data } = useQuery(["health"], healthPing, {
refetchInterval: HEALTH_PING_INTERVAL, refetchInterval: HEALTH_PING_INTERVAL,
@ -33,16 +37,20 @@ export default function StatusDisplay({ className }: { className?: string }) {
if (data[0] === "OK") { if (data[0] === "OK") {
setStatusMessage(successMessage); setStatusMessage(successMessage);
setStatusClass(SuccessStatus); setStatusClass(SuccessStatus);
// catch an auto play error
dingRef.current?.play().catch((e) => {
console.log('DING!')
});
} else { } else {
setStatusMessage(errorMessage); setStatusMessage(errorMessage);
setStatusClass(ErrorStatus); setStatusClass(ErrorStatus);
} }
} }
}, [status, data]); }, [status, data, dingRef]);
return ( return (
<> <>
{/* alittle hacky but joins the class names, will probably need a better css in js solution or tailwinds */} <AudioDing ref={dingRef}></AudioDing>
<p className={[statusClass, className].join(" ")}>{statusMessage}</p> <p className={[statusClass, className].join(" ")}>{statusMessage}</p>
</> </>
); );

File diff suppressed because one or more lines are too long