mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
move api params to app
This commit is contained in:
parent
6233b0d70d
commit
0fad202491
@ -19,6 +19,7 @@ import AppErrorBoundaryFallback from './AppErrorBoundaryFallback';
|
|||||||
import GlobalHotkeys from './GlobalHotkeys';
|
import GlobalHotkeys from './GlobalHotkeys';
|
||||||
import Toaster from './Toaster';
|
import Toaster from './Toaster';
|
||||||
import { api } from '../../services/api';
|
import { api } from '../../services/api';
|
||||||
|
import { $authToken, $baseUrl, $projectId } from 'services/api/client';
|
||||||
|
|
||||||
const DEFAULT_CONFIG = {};
|
const DEFAULT_CONFIG = {};
|
||||||
|
|
||||||
@ -29,12 +30,18 @@ interface Props {
|
|||||||
imageName: string;
|
imageName: string;
|
||||||
action: 'sendToImg2Img' | 'sendToCanvas' | 'useAllParameters';
|
action: 'sendToImg2Img' | 'sendToCanvas' | 'useAllParameters';
|
||||||
};
|
};
|
||||||
|
apiUrl?: string;
|
||||||
|
token?: string;
|
||||||
|
projectId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const App = ({
|
const App = ({
|
||||||
config = DEFAULT_CONFIG,
|
config = DEFAULT_CONFIG,
|
||||||
headerComponent,
|
headerComponent,
|
||||||
selectedImage,
|
selectedImage,
|
||||||
|
apiUrl,
|
||||||
|
token,
|
||||||
|
projectId,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
const language = useAppSelector(languageSelector);
|
const language = useAppSelector(languageSelector);
|
||||||
|
|
||||||
@ -47,6 +54,31 @@ const App = ({
|
|||||||
return false;
|
return false;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// configure API client token
|
||||||
|
if (token) {
|
||||||
|
$authToken.set(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
// configure API client base url
|
||||||
|
if (apiUrl) {
|
||||||
|
$baseUrl.set(apiUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
// configure API client project header
|
||||||
|
if (projectId) {
|
||||||
|
$projectId.set(projectId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
// Reset the API client token and base url on unmount
|
||||||
|
$baseUrl.set(undefined);
|
||||||
|
$authToken.set(undefined);
|
||||||
|
$projectId.set(undefined);
|
||||||
|
dispatch(api.util.resetApiState());
|
||||||
|
};
|
||||||
|
}, [apiUrl, token, projectId, dispatch]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
i18n.changeLanguage(language);
|
i18n.changeLanguage(language);
|
||||||
}, [language]);
|
}, [language]);
|
||||||
@ -66,12 +98,6 @@ const App = ({
|
|||||||
handlePreselectedImage(selectedImage);
|
handlePreselectedImage(selectedImage);
|
||||||
}, [handlePreselectedImage, selectedImage]);
|
}, [handlePreselectedImage, selectedImage]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
return () => {
|
|
||||||
dispatch(api.util.resetApiState());
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ErrorBoundary
|
<ErrorBoundary
|
||||||
onReset={handleReset}
|
onReset={handleReset}
|
||||||
|
@ -10,7 +10,6 @@ import React, {
|
|||||||
} 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';
|
||||||
import { $authToken, $baseUrl, $projectId } from 'services/api/client';
|
|
||||||
import { socketMiddleware } from 'services/events/middleware';
|
import { socketMiddleware } from 'services/events/middleware';
|
||||||
import Loading from '../../common/components/Loading/Loading';
|
import Loading from '../../common/components/Loading/Loading';
|
||||||
import '../../i18n';
|
import '../../i18n';
|
||||||
@ -42,21 +41,6 @@ const InvokeAIUI = ({
|
|||||||
selectedImage,
|
selectedImage,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// configure API client token
|
|
||||||
if (token) {
|
|
||||||
$authToken.set(token);
|
|
||||||
}
|
|
||||||
|
|
||||||
// configure API client base url
|
|
||||||
if (apiUrl) {
|
|
||||||
$baseUrl.set(apiUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
// configure API client project header
|
|
||||||
if (projectId) {
|
|
||||||
$projectId.set(projectId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// reset dynamically added middlewares
|
// reset dynamically added middlewares
|
||||||
resetMiddlewares();
|
resetMiddlewares();
|
||||||
|
|
||||||
@ -71,14 +55,7 @@ const InvokeAIUI = ({
|
|||||||
} else {
|
} else {
|
||||||
addMiddleware(socketMiddleware());
|
addMiddleware(socketMiddleware());
|
||||||
}
|
}
|
||||||
|
}, [middleware]);
|
||||||
return () => {
|
|
||||||
// Reset the API client token and base url on unmount
|
|
||||||
$baseUrl.set(undefined);
|
|
||||||
$authToken.set(undefined);
|
|
||||||
$projectId.set(undefined);
|
|
||||||
};
|
|
||||||
}, [apiUrl, token, middleware, projectId]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
@ -90,6 +67,9 @@ const InvokeAIUI = ({
|
|||||||
config={config}
|
config={config}
|
||||||
headerComponent={headerComponent}
|
headerComponent={headerComponent}
|
||||||
selectedImage={selectedImage}
|
selectedImage={selectedImage}
|
||||||
|
apiUrl={apiUrl}
|
||||||
|
token={token}
|
||||||
|
projectId={projectId}
|
||||||
/>
|
/>
|
||||||
</AppDndContext>
|
</AppDndContext>
|
||||||
</ThemeLocaleProvider>
|
</ThemeLocaleProvider>
|
||||||
|
Loading…
Reference in New Issue
Block a user