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"
2
11
import { CancelToken } from "navigraph/auth"
3
12
import { packages } from "../Lib/navigraph"
4
13
import { AuthService } from "../Services/AuthService"
@@ -8,6 +17,7 @@ import {
8
17
NavigraphEventType ,
9
18
NavigraphNavigationDataInterface ,
10
19
} from "@navigraph/msfs-navigation-data-interface"
20
+ import { NavigationDataStatus } from "@navigraph/msfs-navigation-data-interface/types/meta"
11
21
import { Dropdown } from "./Dropdown"
12
22
import { Input } from "./Input"
13
23
@@ -28,6 +38,8 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
28
38
private readonly executeSqlButtonRef = FSComponent . createRef < HTMLButtonElement > ( )
29
39
private readonly outputRef = FSComponent . createRef < HTMLPreElement > ( )
30
40
41
+ private readonly navigationDataStatus = Subject . create < NavigationDataStatus | null > ( null )
42
+
31
43
private cancelSource = CancelToken . source ( )
32
44
33
45
private navigationDataInterface : NavigraphNavigationDataInterface
@@ -57,6 +69,36 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
57
69
} )
58
70
}
59
71
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
+
60
102
public render ( ) : VNode {
61
103
return (
62
104
< div class = "auth-container" >
@@ -74,6 +116,7 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
74
116
< div ref = { this . downloadButtonRef } class = "button" >
75
117
Download
76
118
</ div >
119
+ { this . renderDatabaseStatus ( ) }
77
120
</ div >
78
121
</ div >
79
122
@@ -109,6 +152,16 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
109
152
this . loginButtonRef . instance . addEventListener ( "click" , ( ) => this . handleClick ( ) )
110
153
this . downloadButtonRef . instance . addEventListener ( "click" , ( ) => this . handleDownloadClick ( ) )
111
154
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
+
112
165
this . executeIcaoButtonRef . instance . addEventListener ( "click" , ( ) => {
113
166
console . time ( "query" )
114
167
this . navigationDataInterface
@@ -197,6 +250,15 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
197
250
198
251
// Download navigation data to work dir
199
252
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
+
200
262
this . displayMessage ( "Navigation data downloaded" )
201
263
} catch ( err ) {
202
264
if ( err instanceof Error ) this . displayError ( err . message )
0 commit comments