diff --git a/gui/.eslintrc.json b/gui/.eslintrc.json index f806fb28..4b00d6e4 100644 --- a/gui/.eslintrc.json +++ b/gui/.eslintrc.json @@ -229,7 +229,12 @@ "no-redeclare": "off", "no-restricted-syntax": [ "error", - "ForInStatement" + "ForInStatement", + "WithStatement", + "MemberExpression[optional=true]", + "IfStatement[alternate.type='IfStatement']", + "UnaryExpression[operator='!']", + "BinaryExpression[operator='==='][right.value=true]" ], "no-return-await": "error", "no-sequences": "error", diff --git a/gui/src/components/LoadingCard.tsx b/gui/src/components/LoadingCard.tsx index 4e587388..69cdefac 100644 --- a/gui/src/components/LoadingCard.tsx +++ b/gui/src/components/LoadingCard.tsx @@ -1,4 +1,4 @@ -import { mustExist } from '@apextoaster/js-utils'; +import { doesExist, mustExist } from '@apextoaster/js-utils'; import { Card, CardContent, CircularProgress } from '@mui/material'; import * as React from 'react'; import { useContext } from 'react'; @@ -20,17 +20,21 @@ export function LoadingCard(props: LoadingCardProps) { // eslint-disable-next-line @typescript-eslint/unbound-method const pushHistory = useStore(mustExist(useContext(StateContext)), (state) => state.pushHistory); - const ready = useQuery('ready', () => client.ready(props.loading), { + const query = useQuery('ready', () => client.ready(props.loading), { // data will always be ready without this, even if the API says its not cacheTime: 0, refetchInterval: POLL_TIME, }); + function ready() { + return doesExist(query.data) && query.data.ready; + } + React.useEffect(() => { - if (ready.status === 'success' && ready.data.ready) { + if (query.status === 'success' && query.data.ready) { pushHistory(props.loading); } - }, [ready.status, ready.data?.ready]); + }, [query.status, ready()]); return diff --git a/gui/src/components/OnnxWeb.tsx b/gui/src/components/OnnxWeb.tsx index f3b1ec64..1a115802 100644 --- a/gui/src/components/OnnxWeb.tsx +++ b/gui/src/components/OnnxWeb.tsx @@ -1,17 +1,16 @@ import { TabContext, TabList, TabPanel } from '@mui/lab'; import { Box, Container, Divider, Link, Tab, Typography } from '@mui/material'; import * as React from 'react'; +import { useState } from 'react'; +import { ModelControl } from './control/ModelControl.js'; import { ImageHistory } from './ImageHistory.js'; import { Img2Img } from './tab/Img2Img.js'; import { Inpaint } from './tab/Inpaint.js'; -import { ModelControl } from './control/ModelControl.js'; import { Settings } from './tab/Settings.js'; import { Txt2Img } from './tab/Txt2Img.js'; import { Upscale } from './tab/Upscale.js'; -const { useState } = React; - export function OnnxWeb() { const [tab, setTab] = useState('txt2img'); diff --git a/gui/src/components/control/ImageControl.tsx b/gui/src/components/control/ImageControl.tsx index 829f0567..6420cfba 100644 --- a/gui/src/components/control/ImageControl.tsx +++ b/gui/src/components/control/ImageControl.tsx @@ -2,6 +2,7 @@ import { doesExist, mustDefault, mustExist } from '@apextoaster/js-utils'; import { Casino } from '@mui/icons-material'; import { Button, Stack, TextField } from '@mui/material'; import * as React from 'react'; +import { useContext } from 'react'; import { useQuery } from 'react-query'; import { useStore } from 'zustand'; @@ -12,8 +13,6 @@ import { SCHEDULER_LABELS } from '../../strings.js'; import { NumericField } from '../input/NumericField.js'; import { QueryList } from '../input/QueryList.js'; -const { useContext } = React; - export const PROMPT_LIMIT = 70; export interface ImageControlProps { diff --git a/gui/src/components/error/ServerParams.tsx b/gui/src/components/error/ServerParams.tsx index f82e4cad..b52ff6de 100644 --- a/gui/src/components/error/ServerParams.tsx +++ b/gui/src/components/error/ServerParams.tsx @@ -9,11 +9,13 @@ export interface ServerParamsErrorProps { function getErrorMessage(error: unknown): string { if (error instanceof Error) { return error.message; - } else if (typeof error === 'string') { - return error; - } else { - return 'unknown error'; } + + if (typeof error === 'string') { + return error; + } + + return 'unknown error'; } export function ServerParamsError(props: ServerParamsErrorProps) { diff --git a/gui/src/components/tab/Img2Img.tsx b/gui/src/components/tab/Img2Img.tsx index 8a2840d8..e4cbd981 100644 --- a/gui/src/components/tab/Img2Img.tsx +++ b/gui/src/components/tab/Img2Img.tsx @@ -1,17 +1,16 @@ import { doesExist, mustExist } from '@apextoaster/js-utils'; import { Box, Button, Stack } from '@mui/material'; import * as React from 'react'; +import { useContext } from 'react'; import { useMutation, useQueryClient } from 'react-query'; import { useStore } from 'zustand'; import { IMAGE_FILTER } from '../../config.js'; import { ClientContext, ConfigContext, StateContext } from '../../state.js'; import { ImageControl } from '../control/ImageControl.js'; +import { UpscaleControl } from '../control/UpscaleControl.js'; import { ImageInput } from '../input/ImageInput.js'; import { NumericField } from '../input/NumericField.js'; -import { UpscaleControl } from '../control/UpscaleControl.js'; - -const { useContext } = React; export function Img2Img() { const { params } = mustExist(useContext(ConfigContext)); diff --git a/gui/src/components/tab/Inpaint.tsx b/gui/src/components/tab/Inpaint.tsx index d763b6d7..214caeb6 100644 --- a/gui/src/components/tab/Inpaint.tsx +++ b/gui/src/components/tab/Inpaint.tsx @@ -1,6 +1,7 @@ import { doesExist, mustExist } from '@apextoaster/js-utils'; import { Box, Button, FormControlLabel, Stack } from '@mui/material'; import * as React from 'react'; +import { useContext } from 'react'; import { useMutation, useQuery, useQueryClient } from 'react-query'; import { useStore } from 'zustand'; @@ -8,14 +9,12 @@ import { IMAGE_FILTER, STALE_TIME } from '../../config.js'; import { ClientContext, ConfigContext, StateContext } from '../../state.js'; import { MASK_LABELS, NOISE_LABELS } from '../../strings.js'; import { ImageControl } from '../control/ImageControl.js'; +import { OutpaintControl } from '../control/OutpaintControl.js'; +import { UpscaleControl } from '../control/UpscaleControl.js'; import { ImageInput } from '../input/ImageInput.js'; import { MaskCanvas } from '../input/MaskCanvas.js'; import { NumericField } from '../input/NumericField.js'; -import { OutpaintControl } from '../control/OutpaintControl.js'; import { QueryList } from '../input/QueryList.js'; -import { UpscaleControl } from '../control/UpscaleControl.js'; - -const { useContext } = React; export function Inpaint() { const { params } = mustExist(useContext(ConfigContext)); diff --git a/gui/src/components/tab/Txt2Img.tsx b/gui/src/components/tab/Txt2Img.tsx index 61e8ba83..53424bdc 100644 --- a/gui/src/components/tab/Txt2Img.tsx +++ b/gui/src/components/tab/Txt2Img.tsx @@ -1,15 +1,14 @@ import { mustExist } from '@apextoaster/js-utils'; import { Box, Button, Stack } from '@mui/material'; import * as React from 'react'; +import { useContext } from 'react'; import { useMutation, useQueryClient } from 'react-query'; import { useStore } from 'zustand'; import { ClientContext, ConfigContext, StateContext } from '../../state.js'; import { ImageControl } from '../control/ImageControl.js'; -import { NumericField } from '../input/NumericField.js'; import { UpscaleControl } from '../control/UpscaleControl.js'; - -const { useContext } = React; +import { NumericField } from '../input/NumericField.js'; export function Txt2Img() { const { params } = mustExist(useContext(ConfigContext)); diff --git a/gui/src/components/tab/Upscale.tsx b/gui/src/components/tab/Upscale.tsx index a7d20442..c56d337d 100644 --- a/gui/src/components/tab/Upscale.tsx +++ b/gui/src/components/tab/Upscale.tsx @@ -1,15 +1,14 @@ import { doesExist, mustExist } from '@apextoaster/js-utils'; import { Box, Button, Stack } from '@mui/material'; import * as React from 'react'; +import { useContext } from 'react'; import { useMutation, useQueryClient } from 'react-query'; import { useStore } from 'zustand'; import { IMAGE_FILTER } from '../../config.js'; -import { ClientContext, ConfigContext, StateContext } from '../../state.js'; -import { ImageInput } from '../input/ImageInput.js'; +import { ClientContext, StateContext } from '../../state.js'; import { UpscaleControl } from '../control/UpscaleControl.js'; - -const { useContext } = React; +import { ImageInput } from '../input/ImageInput.js'; export function Upscale() { async function uploadSource() { @@ -38,11 +37,16 @@ export function Upscale() { return - { - setSource({ - source: file, - }); - }} /> + { + setSource({ + source: file, + }); + }} + />