diff --git a/apps/studio/src/services/app.service.ts b/apps/studio/src/services/app.service.ts index 978c7871b..bc2dbd8b2 100644 --- a/apps/studio/src/services/app.service.ts +++ b/apps/studio/src/services/app.service.ts @@ -11,11 +11,12 @@ export class ApplicationService extends AbstractService { // subscribe to state to hide preloader this.hidePreloader(); - const { readOnly, url, base64 } = this.svcs.navigationSvc.getUrlParameters(); + const { readOnly, url, base64 } = + this.svcs.navigationSvc.getUrlParameters(); // readOnly state should be only set to true when someone pass also url or base64 parameter const isStrictReadonly = Boolean(readOnly && (url || base64)); - let error: any; + let error: any; try { await this.fetchResource(url, base64); } catch (err) { @@ -23,6 +24,10 @@ export class ApplicationService extends AbstractService { console.error(err); } + if (error) { + appState.setState({ initErrors: [error] }); + } + if (isStrictReadonly && !error) { appState.setState({ readOnly, @@ -32,7 +37,8 @@ export class ApplicationService extends AbstractService { } public async afterAppInit() { - const { readOnly, url, base64, redirectedFrom } = this.svcs.navigationSvc.getUrlParameters(); + const { readOnly, url, base64, redirectedFrom } = + this.svcs.navigationSvc.getUrlParameters(); const isStrictReadonly = Boolean(readOnly && (url || base64)); // show RedirectedModal modal if the redirectedFrom is set (only when readOnly state is set to false) @@ -45,11 +51,11 @@ export class ApplicationService extends AbstractService { if (!url && !base64) { return; } - + const { updateFile } = filesState.getState(); let content = ''; if (url) { - content = await fetch(url).then(res => res.text()); + content = await fetch(url).then((res) => res.text()); } else if (base64) { content = this.svcs.formatSvc.decodeBase64(base64); } @@ -79,4 +85,4 @@ export class ApplicationService extends AbstractService { } }); } -} \ No newline at end of file +} diff --git a/apps/studio/src/state/app.state.ts b/apps/studio/src/state/app.state.ts index 3ebeab6c0..40af06b1b 100644 --- a/apps/studio/src/state/app.state.ts +++ b/apps/studio/src/state/app.state.ts @@ -4,12 +4,14 @@ export type AppState = { initialized: boolean; readOnly: boolean; liveServer: boolean; + initErrors: any[], } export const appState = create(() => ({ initialized: false, readOnly: false, liveServer: false, + initErrors: [], })); export const useAppState = appState; \ No newline at end of file diff --git a/apps/studio/src/studio.tsx b/apps/studio/src/studio.tsx index 8837af4c9..ba60207fc 100644 --- a/apps/studio/src/studio.tsx +++ b/apps/studio/src/studio.tsx @@ -1,5 +1,5 @@ import React, { useEffect } from 'react'; -import { Toaster } from 'react-hot-toast'; +import toast, { Toaster } from 'react-hot-toast'; import { Content, Sidebar, Template, Toolbar } from './components'; @@ -8,7 +8,9 @@ import { appState } from './state'; export interface AsyncAPIStudioProps {} -export const AsyncAPIStudio: React.FunctionComponent = () => { +export const AsyncAPIStudio: React.FunctionComponent< + AsyncAPIStudioProps +> = () => { const services = useServices(); useEffect(() => { @@ -24,6 +26,13 @@ export const AsyncAPIStudio: React.FunctionComponent = () = ); } + const unsubscribe = appState.subscribe((state) => { + state.initErrors.forEach((e) => { + toast.error(e.message); + }); + unsubscribe(); + appState.setState({ initErrors: [] }); + }); return (