Skip to content

Commit 93b96aa

Browse files
committed
feat: display install status on display
1 parent 22c4a67 commit 93b96aa

File tree

2 files changed

+64
-2
lines changed

2 files changed

+64
-2
lines changed

examples/gauge/Components/Input.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class Input extends DisplayComponent<InputProps> {
4747
render() {
4848
if (this.props.textarea)
4949
return (
50-
<textarea style="width:350px;height:180px;" ref={this.inputRef} {...this.getInputProps()}>
50+
<textarea style="width:350px;height:100px;" ref={this.inputRef} {...this.getInputProps()}>
5151
{this.props.value}
5252
</textarea>
5353
)

examples/gauge/Components/InterfaceSample.tsx

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
import { ComponentProps, DisplayComponent, EventBus, FSComponent, VNode } from "@microsoft/msfs-sdk"
1+
import {
2+
ComponentProps,
3+
DisplayComponent,
4+
EventBus,
5+
FSComponent,
6+
MappedSubject,
7+
ObjectSubject,
8+
Subject,
9+
VNode,
10+
} from "@microsoft/msfs-sdk"
211
import { CancelToken } from "navigraph/auth"
312
import { packages } from "../Lib/navigraph"
413
import { AuthService } from "../Services/AuthService"
@@ -8,6 +17,7 @@ import {
817
NavigraphEventType,
918
NavigraphNavigationDataInterface,
1019
} from "@navigraph/msfs-navigation-data-interface"
20+
import { NavigationDataStatus } from "@navigraph/msfs-navigation-data-interface/types/meta"
1121
import { Dropdown } from "./Dropdown"
1222
import { Input } from "./Input"
1323

@@ -28,6 +38,8 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
2838
private readonly executeSqlButtonRef = FSComponent.createRef<HTMLButtonElement>()
2939
private readonly outputRef = FSComponent.createRef<HTMLPreElement>()
3040

41+
private readonly navigationDataStatus = Subject.create<NavigationDataStatus | null>(null)
42+
3143
private cancelSource = CancelToken.source()
3244

3345
private navigationDataInterface: NavigraphNavigationDataInterface
@@ -57,6 +69,36 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
5769
})
5870
}
5971

72+
public renderDatabaseStatus(): VNode | void {
73+
return (
74+
<>
75+
<div
76+
class={MappedSubject.create(([status]) => {
77+
return status ? "vertical" : "hidden"
78+
}, this.navigationDataStatus)}
79+
>
80+
<div>{this.navigationDataStatus.map(s => `Install method: ${s?.status}`)}</div>
81+
<div>
82+
{this.navigationDataStatus.map(
83+
s => `Installed format: ${s?.installedFormat} revision ${s?.installedRevision}`,
84+
)}
85+
</div>
86+
<div>{this.navigationDataStatus.map(s => `Installed path: ${s?.installedPath}`)}</div>
87+
<div>{this.navigationDataStatus.map(s => `Installed cycle: ${s?.installedCycle}`)}</div>
88+
<div>{this.navigationDataStatus.map(s => `Latest cycle: ${s?.latestCycle}`)}</div>
89+
<div>{this.navigationDataStatus.map(s => `Validity period: ${s?.validityPeriod}`)}</div>
90+
</div>
91+
<div
92+
class={MappedSubject.create(([status]) => {
93+
return status ? "hidden" : "visible"
94+
}, this.navigationDataStatus)}
95+
>
96+
Loading status...
97+
</div>
98+
</>
99+
)
100+
}
101+
60102
public render(): VNode {
61103
return (
62104
<div class="auth-container">
@@ -74,6 +116,7 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
74116
<div ref={this.downloadButtonRef} class="button">
75117
Download
76118
</div>
119+
{this.renderDatabaseStatus()}
77120
</div>
78121
</div>
79122

@@ -109,6 +152,16 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
109152
this.loginButtonRef.instance.addEventListener("click", () => this.handleClick())
110153
this.downloadButtonRef.instance.addEventListener("click", () => this.handleDownloadClick())
111154

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+
112165
this.executeIcaoButtonRef.instance.addEventListener("click", () => {
113166
console.time("query")
114167
this.navigationDataInterface
@@ -197,6 +250,15 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
197250

198251
// Download navigation data to work dir
199252
await this.navigationDataInterface.download_navigation_data(pkg.file.url)
253+
254+
// Update navigation data status
255+
this.navigationDataInterface
256+
.get_navigation_data_install_status()
257+
.then(status => {
258+
this.navigationDataStatus.set(status)
259+
})
260+
.catch(e => console.error(e))
261+
200262
this.displayMessage("Navigation data downloaded")
201263
} catch (err) {
202264
if (err instanceof Error) this.displayError(err.message)

0 commit comments

Comments
 (0)