clean ups

This commit is contained in:
caranicas 2022-09-27 09:28:04 -04:00
parent 986b303f2f
commit 7a076f7304
6 changed files with 69 additions and 84 deletions

View File

@ -24,7 +24,6 @@ import {
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import AudioDing from "../../../../molecules/audioDing"; import AudioDing from "../../../../molecules/audioDing";
import { debug } from "console";
export default function MakeButton() { export default function MakeButton() {
const { t } = useTranslation(); const { t } = useTranslation();
@ -91,8 +90,7 @@ export default function MakeButton() {
} }
catch (e) { catch (e) {
console.error("Error HACKING JSON: ", e) console.log("Error HACKING JSON: ", e)
// debugger;
} }
} }
@ -152,8 +150,6 @@ export default function MakeButton() {
} }
const startStream = async (id: string, req: ImageRequest) => { const startStream = async (id: string, req: ImageRequest) => {
console.log('START STREAM', id);
const streamReq = { const streamReq = {
...req, ...req,
stream_image_progress: true, stream_image_progress: true,
@ -230,7 +226,7 @@ export default function MakeButton() {
useEffect(() => { useEffect(() => {
const makeImages = async (options: ImageRequest) => { const makeImages = async (options: ImageRequest) => {
// potentially update the seed // potentially update the seed
await startStream(id, options); await startStream(id ?? "", options);
} }
if (status === FetchingStates.PROGRESSING || status === FetchingStates.FETCHING) { if (status === FetchingStates.PROGRESSING || status === FetchingStates.FETCHING) {
@ -238,6 +234,11 @@ export default function MakeButton() {
} }
if (hasQueue) { if (hasQueue) {
if (options === undefined) {
console.log('req is undefined');
return;
}
makeImages(options).catch((e) => { makeImages(options).catch((e) => {
console.log('HAS QUEUE ERROR'); console.log('HAS QUEUE ERROR');
console.log(e); console.log(e);

View File

@ -1,7 +1,5 @@
import React from "react"; import React from "react";
import { CompletedImagesType } from "../currentDisplay";
import { useImageDisplay } from "../../../../stores/imageDisplayStore"; import { useImageDisplay } from "../../../../stores/imageDisplayStore";
@ -25,11 +23,6 @@ export default function CompletedImages(
const clearDisplay = useImageDisplay((state) => state.clearDisplay); const clearDisplay = useImageDisplay((state) => state.clearDisplay);
// const _handleSetCurrentDisplay = (index: number) => {
// const image = images![index];
// setCurrentDisplay(image);
// };
const removeImagesAll = () => { const removeImagesAll = () => {
clearDisplay(); clearDisplay();
}; };

View File

@ -1,18 +1,14 @@
/* eslint-disable @typescript-eslint/restrict-template-expressions */
/* eslint-disable multiline-ternary */
/* eslint-disable @typescript-eslint/naming-convention */ /* eslint-disable @typescript-eslint/naming-convention */
/* eslint-disable multiline-ternary */
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import GeneratedImage from "../../../molecules/generatedImage"; import GeneratedImage from "../../../molecules/generatedImage";
import { ImageRequest, useImageCreate } from "../../../../stores/imageCreateStore"; import { useImageCreate } from "../../../../stores/imageCreateStore";
import { FetchingStates, useImageFetching } from "../../../../stores/imageFetchingStore"; import { FetchingStates, useImageFetching } from "../../../../stores/imageFetchingStore";
import { useImageDisplay } from "../../../../stores/imageDisplayStore"; import { CompletedImagesType, useImageDisplay } from "../../../../stores/imageDisplayStore";
import { API_URL } from "../../../../api";
export interface CompletedImagesType {
id?: string;
data: string | undefined;
info: ImageRequest | undefined;
}
const IdleDisplay = () => { const IdleDisplay = () => {
return ( return (
@ -44,7 +40,7 @@ const LoadingDisplay = () => {
<p>{percent} % Complete </p> <p>{percent} % Complete </p>
{progressImages.map((image, index) => { {progressImages.map((image, index) => {
return ( return (
<img src={`http://localhost:9000${image}`} key={index} /> <img src={`${API_URL}${image}`} key={index} />
) )
}) })
} }
@ -93,7 +89,7 @@ const ImageDisplay = ({ info, data }: CompletedImagesType) => {
const _handleSave = () => { const _handleSave = () => {
const link = document.createElement("a"); const link = document.createElement("a");
link.download = createFileName(); link.download = createFileName();
link.href = data!; link.href = data ?? "";
link.click(); link.click();
}; };
@ -101,8 +97,6 @@ const ImageDisplay = ({ info, data }: CompletedImagesType) => {
setRequestOption("init_image", data); setRequestOption("init_image", data);
}; };
return ( return (
<div className="imageDisplay"> <div className="imageDisplay">
<p> {info?.prompt}</p> <p> {info?.prompt}</p>
@ -120,24 +114,6 @@ export default function CurrentDisplay() {
const status = useImageFetching((state) => state.status); const status = useImageFetching((state) => state.status);
const currentImage = useImageDisplay((state) => state.currentImage); const currentImage = useImageDisplay((state) => state.currentImage);
console.log("currentImage", currentImage);
// const [currentImage, setCurrentImage] = useState<CompletedImagesType | null>(
// null
// );
// const testCur = useImageDisplay((state) => state.getCurrentImage());
// const images = useImageDisplay((state) => state.images);
// useEffect(() => {
// if (images.length > 0) {
// console.log("cur", images[0]);
// setCurrentImage(images[0]);
// } else {
// setCurrentImage(null);
// }
// }, [images]);
return ( return (
<div className="current-display"> <div className="current-display">

View File

@ -2,12 +2,21 @@
import create from "zustand"; import create from "zustand";
import produce from "immer"; import produce from "immer";
import { ImageRequest } from "./imageCreateStore";
export interface CompletedImagesType {
id?: string;
data: string | undefined;
info: ImageRequest;
}
interface ImageDisplayState { interface ImageDisplayState {
// imageOptions: Map<string, any>; // imageOptions: Map<string, any>;
images: object[] images: CompletedImagesType[]
currentImage: object | null currentImage: CompletedImagesType | null
updateDisplay: (ImageData: string, imageOptions: any) => void; updateDisplay: (ImageData: string, imageOptions: any) => void;
setCurrentImage: (image: object) => void; setCurrentImage: (image: CompletedImagesType) => void;
clearDisplay: () => void; clearDisplay: () => void;
// getCurrentImage: () => {}; // getCurrentImage: () => {};

View File

@ -4,12 +4,18 @@ import { useRandomSeed } from "../utils";
import { ImageRequest } from "./imageCreateStore"; import { ImageRequest } from "./imageCreateStore";
interface QueueItem {
id?: string;
options?: ImageRequest;
status?: "pending" | "complete" | "error";
}
interface ImageQueueState { interface ImageQueueState {
images: ImageRequest[]; images: QueueItem[];
completedImageIds: string[]; completedImageIds: string[];
addNewImage: (id: string, imgRec: ImageRequest) => void; addNewImage: (id: string, imgRec: ImageRequest) => void;
hasQueuedImages: () => boolean; hasQueuedImages: () => boolean;
firstInQueue: () => ImageRequest | {}; firstInQueue: () => QueueItem;
removeFirstInQueue: () => void; removeFirstInQueue: () => void;
clearCachedIds: () => void; clearCachedIds: () => void;
} }
@ -18,17 +24,11 @@ export const useImageQueue = create<ImageQueueState>((set, get) => ({
images: [], images: [],
completedImageIds: [], completedImageIds: [],
// use produce to make sure we don't mutate state // use produce to make sure we don't mutate state
addNewImage: (id: string, imgRec: ImageRequest, isRandom = false) => { addNewImage: (id: string, imgRec: ImageRequest) => {
set( set(
produce((state) => { produce((state) => {
let { seed } = imgRec; const item: QueueItem = { id, options: imgRec, status: "pending" };
if (isRandom) { state.images.push(item);
seed = useRandomSeed();
}
const newImg = { id, options: { ...imgRec, seed } };
console.log("addNewImage", newImg);
state.images.push(newImg);
}) })
); );
}, },
@ -38,18 +38,24 @@ export const useImageQueue = create<ImageQueueState>((set, get) => ({
}, },
firstInQueue: () => { firstInQueue: () => {
let first: ImageRequest | {} = get().images[0]; const { images } = get();
first = void 0 !== first ? first : {}; if (images.length > 0) {
return first; return images[0];
}
// // cast an empty object to QueueItem
const empty: QueueItem = {};
return empty;
}, },
removeFirstInQueue: () => { removeFirstInQueue: () => {
set( set(
produce((state) => { produce((state) => {
console.log("removing first in queue");
const image = state.images.shift(); const image = state.images.shift();
console.log("image", image); console.log("image", image);
// state.completedImageIds.push(image.id); if (void 0 !== image) {
state.completedImageIds.push(image.id);
}
}) })
); );
}, },

File diff suppressed because one or more lines are too long