@@ -22,6 +22,7 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
22
22
private readonly dropdownRef = FSComponent . createRef < Dropdown > ( )
23
23
private readonly downloadButtonRef = FSComponent . createRef < HTMLButtonElement > ( )
24
24
private readonly executeButtonRef = FSComponent . createRef < HTMLButtonElement > ( )
25
+ private readonly setActiveButtonRef = FSComponent . createRef < HTMLButtonElement > ( )
25
26
private readonly inputRef = FSComponent . createRef < HTMLInputElement > ( )
26
27
27
28
private cancelSource = CancelToken . source ( )
@@ -33,13 +34,6 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
33
34
34
35
this . navigationDataInterface = new NavigraphNavigationDataInterface ( )
35
36
36
- this . navigationDataInterface . onReady ( ( ) => {
37
- this . navigationDataInterface
38
- . set_active_database ( "avionics_v2" )
39
- . then ( ( ) => console . info ( "WASM set active database" ) )
40
- . catch ( err => this . displayError ( String ( err ) ) )
41
- } )
42
-
43
37
this . navigationDataInterface . onEvent ( NavigraphEventType . DownloadProgress , data => {
44
38
switch ( data . phase ) {
45
39
case DownloadProgressPhase . Downloading :
@@ -75,6 +69,9 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
75
69
< div ref = { this . downloadButtonRef } class = "button" >
76
70
Download
77
71
</ div >
72
+ < div ref = { this . setActiveButtonRef } class = "button" >
73
+ Set as Active
74
+ </ div >
78
75
< input ref = { this . inputRef } type = "text" id = "sql" name = "sql" value = "ESSA" class = "text-field" />
79
76
< div ref = { this . executeButtonRef } class = "button" >
80
77
Execute SQL
@@ -106,6 +103,16 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
106
103
. catch ( e => console . error ( e ) )
107
104
} )
108
105
106
+ this . setActiveButtonRef . instance . addEventListener ( "click" , ( ) => {
107
+ const format = this . dropdownRef . instance . getNavigationDataFormat ( )
108
+ if ( ! format ) return
109
+ // This will only work if the database specified is a SQLite database
110
+ this . navigationDataInterface
111
+ . set_active_database ( format )
112
+ . then ( ( ) => console . info ( "WASM set active database" ) )
113
+ . catch ( err => this . displayError ( String ( err ) ) )
114
+ } )
115
+
109
116
AuthService . user . sub ( user => {
110
117
if ( user ) {
111
118
this . qrCodeRef . instance . src = ""
@@ -168,10 +175,6 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
168
175
// Download navigation data to work dir
169
176
await this . navigationDataInterface . download_navigation_data ( pkg . file . url , pkg . format )
170
177
this . displayMessage ( "Navigation data downloaded" )
171
-
172
- // Set active database to recently downloaded package
173
- await this . navigationDataInterface . set_active_database ( pkg . format )
174
- console . info ( "WASM set active database" )
175
178
} catch ( err ) {
176
179
if ( err instanceof Error ) this . displayError ( err . message )
177
180
else this . displayError ( `Unknown error: ${ String ( err ) } ` )
0 commit comments