Skip to content

Commit b963ccb

Browse files
committed
fix: separate set active database
1 parent c5519cb commit b963ccb

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

examples/gauge/Components/InterfaceSample.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
2222
private readonly dropdownRef = FSComponent.createRef<Dropdown>()
2323
private readonly downloadButtonRef = FSComponent.createRef<HTMLButtonElement>()
2424
private readonly executeButtonRef = FSComponent.createRef<HTMLButtonElement>()
25+
private readonly setActiveButtonRef = FSComponent.createRef<HTMLButtonElement>()
2526
private readonly inputRef = FSComponent.createRef<HTMLInputElement>()
2627

2728
private cancelSource = CancelToken.source()
@@ -33,13 +34,6 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
3334

3435
this.navigationDataInterface = new NavigraphNavigationDataInterface()
3536

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-
4337
this.navigationDataInterface.onEvent(NavigraphEventType.DownloadProgress, data => {
4438
switch (data.phase) {
4539
case DownloadProgressPhase.Downloading:
@@ -75,6 +69,9 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
7569
<div ref={this.downloadButtonRef} class="button">
7670
Download
7771
</div>
72+
<div ref={this.setActiveButtonRef} class="button">
73+
Set as Active
74+
</div>
7875
<input ref={this.inputRef} type="text" id="sql" name="sql" value="ESSA" class="text-field" />
7976
<div ref={this.executeButtonRef} class="button">
8077
Execute SQL
@@ -106,6 +103,16 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
106103
.catch(e => console.error(e))
107104
})
108105

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+
109116
AuthService.user.sub(user => {
110117
if (user) {
111118
this.qrCodeRef.instance.src = ""
@@ -168,10 +175,6 @@ export class InterfaceSample extends DisplayComponent<InterfaceSampleProps> {
168175
// Download navigation data to work dir
169176
await this.navigationDataInterface.download_navigation_data(pkg.file.url, pkg.format)
170177
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")
175178
} catch (err) {
176179
if (err instanceof Error) this.displayError(err.message)
177180
else this.displayError(`Unknown error: ${String(err)}`)

0 commit comments

Comments
 (0)