Skip to content

Commit f155c04

Browse files
committed
feat: add loading screen while waiting for wasm to build
1 parent e85a381 commit f155c04

File tree

2 files changed

+66
-46
lines changed

2 files changed

+66
-46
lines changed

examples/gauge/Components/InterfaceSample.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
position: relative;
66
}
77

8+
.loading-container {
9+
display: flex;
10+
justify-content: center;
11+
align-items: center;
12+
width: 100%;
13+
height: 100%;
14+
font-size: x-large;
15+
text-align: center;
16+
}
17+
818
.button {
919
width: 150px;
1020
height: 50px;

examples/gauge/Components/InterfaceSample.tsx

Lines changed: 56 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
MappedSubject,
77
ObjectSubject,
88
Subject,
9+
SubscribableMapFunctions,
910
VNode,
1011
} from "@microsoft/msfs-sdk"
1112
import { CancelToken } from "navigraph/auth"
@@ -39,6 +40,7 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
3940
private readonly outputRef = FSComponent.createRef<HTMLPreElement>()
4041

4142
private readonly navigationDataStatus = Subject.create<NavigationDataStatus | null>(null)
43+
private readonly interfaceInitialized = Subject.create(false)
4244

4345
private cancelSource = CancelToken.source()
4446

@@ -49,6 +51,18 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
4951

5052
this.navigationDataInterface = new NavigraphNavigationDataInterface()
5153

54+
// Populate status when ready
55+
this.navigationDataInterface.onReady(() => {
56+
this.navigationDataInterface
57+
.get_navigation_data_install_status()
58+
.then(status => {
59+
this.navigationDataStatus.set(status)
60+
})
61+
.catch(e => console.error(e))
62+
63+
this.interfaceInitialized.set(true)
64+
})
65+
5266
this.navigationDataInterface.onEvent(NavigraphEventType.DownloadProgress, data => {
5367
switch (data.phase) {
5468
case DownloadProgressPhase.Downloading:
@@ -101,48 +115,54 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
101115

102116
public render(): VNode {
103117
return (
104-
<div class="auth-container">
105-
<div class="horizontal">
106-
<div class="vertical">
107-
<h4>Step 1 - Sign in</h4>
108-
<div ref={this.textRef}>Loading</div>
109-
<div ref={this.loginButtonRef} class="button" />
110-
<div ref={this.navigationDataTextRef} />
111-
<img ref={this.qrCodeRef} class="qr-code" />
112-
</div>
113-
<div class="vertical">
114-
<h4>Step 2 - Select Database</h4>
115-
<Dropdown ref={this.dropdownRef} />
116-
<div ref={this.downloadButtonRef} class="button">
117-
Download
118+
<>
119+
<div class="loading-container" hidden={this.interfaceInitialized}>
120+
Waiting for navigation data interface to initialize... If building for the first time, this may take a few
121+
minutes
122+
</div>
123+
<div class="auth-container" hidden={this.interfaceInitialized.map(SubscribableMapFunctions.not())}>
124+
<div class="horizontal">
125+
<div class="vertical">
126+
<h4>Step 1 - Sign in</h4>
127+
<div ref={this.textRef}>Loading</div>
128+
<div ref={this.loginButtonRef} class="button" />
129+
<div ref={this.navigationDataTextRef} />
130+
<img ref={this.qrCodeRef} class="qr-code" />
131+
</div>
132+
<div class="vertical">
133+
<h4>Step 2 - Select Database</h4>
134+
<Dropdown ref={this.dropdownRef} />
135+
<div ref={this.downloadButtonRef} class="button">
136+
Download
137+
</div>
138+
{this.renderDatabaseStatus()}
118139
</div>
119-
{this.renderDatabaseStatus()}
120140
</div>
121-
</div>
122141

123-
<h4 style="text-align: center;">Step 3 - Query the database</h4>
124-
<div class="horizontal">
125-
<div class="vertical">
126-
<Input ref={this.icaoInputRef} value="ESSA" class="text-field" />
127-
<div ref={this.executeIcaoButtonRef} class="button">
128-
Fetch Airport
129-
</div>
130-
<div style="height:30px;"></div>
131-
<Input
132-
ref={this.sqlInputRef}
133-
textarea
134-
value="SELECT airport_name FROM tbl_airports WHERE airport_identifier = 'ESSA'"
135-
class="text-field"
136-
/>
137-
<div ref={this.executeSqlButtonRef} class="button">
138-
Execute SQL
142+
<h4 style="text-align: center;">Step 3 - Query the database</h4>
143+
<div class="horizontal">
144+
<div class="vertical">
145+
<Input ref={this.icaoInputRef} value="ESSA" class="text-field" />
146+
<div ref={this.executeIcaoButtonRef} class="button">
147+
Fetch Airport
148+
</div>
149+
<div style="height:30px;"></div>
150+
<Input
151+
ref={this.sqlInputRef}
152+
textarea
153+
value="SELECT airport_name FROM tbl_airports WHERE airport_identifier = 'ESSA'"
154+
class="text-field"
155+
/>
156+
<div ref={this.executeSqlButtonRef} class="button">
157+
Execute SQL
158+
</div>
139159
</div>
160+
<pre ref={this.outputRef} id="output">
161+
The output of the query will show up here
162+
</pre>
140163
</div>
141-
<pre ref={this.outputRef} id="output">
142-
The output of the query will show up here
143-
</pre>
144164
</div>
145-
</div>
165+
</>
146166
)
147167
}
148168

@@ -152,16 +172,6 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
152172
this.loginButtonRef.instance.addEventListener("click", () => this.handleClick())
153173
this.downloadButtonRef.instance.addEventListener("click", () => this.handleDownloadClick())
154174

155-
// Populate status when ready
156-
this.navigationDataInterface.onReady(() => {
157-
this.navigationDataInterface
158-
.get_navigation_data_install_status()
159-
.then(status => {
160-
this.navigationDataStatus.set(status)
161-
})
162-
.catch(e => console.error(e))
163-
})
164-
165175
this.executeIcaoButtonRef.instance.addEventListener("click", () => {
166176
console.time("query")
167177
this.navigationDataInterface

0 commit comments

Comments
 (0)