/
lazy-app.tsx
50 lines (46 loc) · 1.5 KB
/
lazy-app.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { IvyScriptLanguage } from '@axonivy/inscription-core';
import {
App,
ClientContextProvider,
MonacoEditorUtil,
QueryProvider,
ThemeContextProvider,
initQueryClient,
type ThemeMode
} from '@axonivy/inscription-editor';
import type { InscriptionClient } from '@axonivy/inscription-protocol';
import type { QueryClient } from '@tanstack/react-query';
import React, { useEffect, useState } from 'react';
export interface LazyAppProps {
clientCreator: () => Promise<InscriptionClient>;
server?: string;
app: string;
pmv: string;
pid: string;
theme: ThemeMode;
}
export function LazyApp(props: LazyAppProps) {
const [client, setClient] = useState<InscriptionClient>();
const [queryClient] = useState<QueryClient>(initQueryClient());
useEffect(() => {
const instance = MonacoEditorUtil.configureInstance({ theme: props.theme, debug: true });
if (props.server) {
IvyScriptLanguage.startWebSocketClient(props.server, instance);
}
props.clientCreator().then(client => setClient(client));
}, [props, props.server, props.theme]);
if (client) {
return (
<React.StrictMode>
<ThemeContextProvider theme={props.theme}>
<ClientContextProvider client={client}>
<QueryProvider client={queryClient}>
<App app={props.app} pmv={props.pmv} pid={props.pid} />
</QueryProvider>
</ClientContextProvider>
</ThemeContextProvider>
</React.StrictMode>
);
}
return <div className='loader' />;
}