Repository navigation
Expand file tree
/
Copy pathApp.tsx
More file actions
54 lines (47 loc) · 1.61 KB
/
Copy pathApp.tsx
File metadata and controls
54 lines (47 loc) · 1.61 KB
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
51
52
53
54
import "./App.scss";
import { Viewer } from "@itwin/web-viewer-react";
import React, { useEffect, useMemo, useState } from "react";
import { MyTokenServerAuthClient } from "./MyTokenServerAuthClient";
import { FillCentered } from "@itwin/core-react";
import { ProgressLinear } from "@itwin/itwinui-react";
const App: React.FC = () => {
const myTokenServerAuthClient = useMemo(() => new MyTokenServerAuthClient(), []);
const [accessToken, setAccessToken] = useState("");
useEffect(() => {
const init = async () => {
await myTokenServerAuthClient.initialize();
const token = await myTokenServerAuthClient.getAccessToken();
setAccessToken(token);
}
init().catch(console.error);
}, [myTokenServerAuthClient]);
if (!process.env.IMJS_ITWIN_ID) {
throw new Error(
"Please add a valid iTwin id to the .env file and restart the application. See the README for more information."
);
}
if (!process.env.IMJS_IMODEL_ID) {
throw new Error(
"Please add a valid iModel id to the .env file and restart the application. See the README for more information."
);
}
return (
<>
{!accessToken && (
<FillCentered>
<div style={{ width: "400px" }}>
<ProgressLinear indeterminate={true} labels={["Signing in..."]} />
</div>
</FillCentered>
)}
<Viewer
iTwinId={process.env.IMJS_ITWIN_ID}
iModelId={process.env.IMJS_IMODEL_ID}
changeSetId={process.env.IMJS_CHANGESET_ID}
authClient={myTokenServerAuthClient}
enablePerformanceMonitors={true}
/>
</>
);
};
export default App;