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"
211import { CancelToken } from "navigraph/auth"
312import { packages } from "../Lib/navigraph"
413import { 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"
1121import { Dropdown } from "./Dropdown"
1222import { 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