dont render app until API is ready

This commit is contained in:
Mary Hipp
2023-08-25 13:34:25 -04:00
parent f67bbadf83
commit bc585ba964

View File

@ -7,6 +7,7 @@ import React, {
PropsWithChildren, PropsWithChildren,
ReactNode, ReactNode,
useEffect, useEffect,
useState,
} from 'react'; } from 'react';
import { Provider } from 'react-redux'; import { Provider } from 'react-redux';
import { addMiddleware, resetMiddlewares } from 'redux-dynamic-middlewares'; import { addMiddleware, resetMiddlewares } from 'redux-dynamic-middlewares';
@ -36,20 +37,19 @@ const InvokeAIUI = ({
middleware, middleware,
projectId, projectId,
}: Props) => { }: Props) => {
const [isReady, setIsReady] = useState(false);
useEffect(() => { useEffect(() => {
// configure API client token if (token && apiUrl && projectId) {
if (token) {
$authToken.set(token); $authToken.set(token);
}
// configure API client base url
if (apiUrl) {
$baseUrl.set(apiUrl); $baseUrl.set(apiUrl);
}
// configure API client project header
if (projectId) {
$projectId.set(projectId); $projectId.set(projectId);
setIsReady(true);
} else if (token && apiUrl) {
$authToken.set(token);
$baseUrl.set(apiUrl);
setIsReady(true);
} else {
setIsReady(true);
} }
// reset dynamically added middlewares // reset dynamically added middlewares
@ -81,7 +81,9 @@ const InvokeAIUI = ({
<React.Suspense fallback={<Loading />}> <React.Suspense fallback={<Loading />}>
<ThemeLocaleProvider> <ThemeLocaleProvider>
<AppDndContext> <AppDndContext>
{isReady && (
<App config={config} headerComponent={headerComponent} /> <App config={config} headerComponent={headerComponent} />
)}
</AppDndContext> </AppDndContext>
</ThemeLocaleProvider> </ThemeLocaleProvider>
</React.Suspense> </React.Suspense>