Skip to content

Commit a3669d8

Browse files
committed
feat: started to implement function selector
1 parent 601085f commit a3669d8

File tree

2 files changed

+157
-6
lines changed

2 files changed

+157
-6
lines changed

examples/gauge/Components/Pages/Dashboard/Dashboard.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ export class Dashboard extends DisplayComponent<DashboardProps> {
6666
render(): VNode {
6767
return (
6868
<div class="size-full flex flex-col">
69-
<p class="mb-8 text-4xl">Dashboard</p>
69+
<p class="ml-2 mb-8 text-4xl">Dashboard</p>
7070
<div class="flex flex-row flex-grow flex-auto">
7171
<div class="w-1/3 flex flex-col">
72-
<p class="text-3xl mb-4">Databases</p>
72+
<p class="ml-2 text-3xl mb-4">Databases</p>
7373
<div class="mt-2 flex-grow bg-ng-background-500 shadow-inner">
7474
<div class="flex flex-col space-y-2">
7575
<List
@@ -99,9 +99,9 @@ class ActiveDatabase extends DisplayComponent<ActiveDatabaseProps> {
9999

100100
render(): VNode {
101101
return (
102-
<div class="flex-grow flex flex-col">
102+
<div class="w-2/3 flex flex-col">
103103
<InterfaceSwitch
104-
class="flex flex-row"
104+
class="ml-2 flex flex-row"
105105
active={this.isActive}
106106
noTheming={true}
107107
intoNoTheming={true}

examples/gauge/Components/Pages/Test/Test.tsx

Lines changed: 153 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,163 @@
1-
import { ComponentProps, DisplayComponent, FSComponent, VNode } from "@microsoft/msfs-sdk"
1+
import {
2+
ComponentProps,
3+
DisplayComponent,
4+
FSComponent,
5+
MappedSubject,
6+
ObjectSubject,
7+
Subject,
8+
VNode,
9+
} from "@microsoft/msfs-sdk"
10+
import { NavigraphNavigationDataInterface } from "@navigraph/msfs-navigation-data-interface"
11+
import { InterfaceNavbarItemV2, InterfaceSwitch } from "../../Utils"
212

3-
interface TestPageProps extends ComponentProps {}
13+
interface TestPageProps extends ComponentProps {
14+
interface: NavigraphNavigationDataInterface
15+
}
16+
17+
interface FunctionDescriptor {
18+
index: number
19+
arguments: string[]
20+
name: string
21+
functionCallback: (input?: string, inputAlt?: string) => unknown
22+
}
23+
24+
interface InputState {
25+
active: boolean
26+
type: InputStateType
27+
}
28+
29+
enum InputStateType {
30+
String,
31+
Bool,
32+
}
433

534
export class TestPage extends DisplayComponent<TestPageProps> {
35+
private readonly selectedFunction = Subject.create(0)
36+
private readonly input1State = ObjectSubject.create<InputState>({
37+
active: false,
38+
type: InputStateType.String,
39+
})
40+
private readonly input2State = ObjectSubject.create<InputState>({
41+
active: false,
42+
type: InputStateType.String,
43+
})
44+
45+
private strToBool(input?: string): boolean {
46+
return input == "true" ? true : false
47+
}
48+
49+
private readonly functionList: FunctionDescriptor[] = [
50+
{
51+
index: 0,
52+
arguments: ["url: string"],
53+
name: "DownloadNavigationData",
54+
functionCallback: input => this.props.interface.download_navigation_data(input ?? ""),
55+
},
56+
{
57+
index: 1,
58+
arguments: [],
59+
name: "GetActivePackage",
60+
functionCallback: () => this.props.interface.get_active_package(),
61+
},
62+
{
63+
index: 2,
64+
arguments: ["sort: bool", "filter: bool"],
65+
name: "ListAvailablePackages",
66+
functionCallback: (input, inputAlt) =>
67+
this.props.interface.list_available_packages(this.strToBool(input), this.strToBool(inputAlt)),
68+
},
69+
{
70+
index: 3,
71+
arguments: ["uuid: string"],
72+
name: "SetActivePackage",
73+
functionCallback: input => this.props.interface.download_navigation_data(input ?? ""),
74+
},
75+
]
76+
77+
private readonly _generateInputs = this.selectedFunction.map(selectedFunction => {
78+
const functionObj = this.functionList[selectedFunction]
79+
80+
const functionArgCount = functionObj.arguments.length
81+
82+
switch (functionArgCount) {
83+
case 1: {
84+
this.input1State.set("active", true)
85+
this.input2State.set("active", false)
86+
break
87+
}
88+
case 2: {
89+
this.input1State.set("active", true)
90+
this.input2State.set("active", true)
91+
break
92+
}
93+
default: {
94+
this.input1State.set("active", false)
95+
this.input2State.set("active", false)
96+
break
97+
}
98+
}
99+
100+
functionObj.arguments.forEach((value, index) => {
101+
const argumentType = value.includes("bool") ? InputStateType.Bool : InputStateType.String
102+
103+
switch (index) {
104+
case 1: {
105+
this.input2State.set("type", argumentType)
106+
break
107+
}
108+
default: {
109+
this.input1State.set("type", argumentType)
110+
break
111+
}
112+
}
113+
})
114+
})
115+
6116
render(): VNode {
7117
return (
8118
<div class="size-full flex flex-col">
9119
<p class="mb-8 text-4xl">Test</p>
120+
<div class="flex flex-row">
121+
<div class="w-1/3 flex flex-col">
122+
<div class="overflow-scroll flex-grow bg-ng-background-500">
123+
{this.functionList.map(obj => (
124+
<InterfaceNavbarItemV2
125+
content={""}
126+
class="w-full p-2 flex flex-col items-start"
127+
activeClass="bg-blue-400"
128+
active={this.selectedFunction.map(index => index === obj.index)}
129+
setActive={() => this.selectedFunction.set(obj.index)}
130+
>
131+
<p class="text-xl">{obj.name}</p>
132+
<p class="text-lg">({obj.arguments.join(", ")})</p>
133+
</InterfaceNavbarItemV2>
134+
))}
135+
</div>
136+
<div class="flex flex-row">
137+
<InterfaceSwitch
138+
active={this.input1State.map(obj => {
139+
return obj.active ? (obj.type === InputStateType.String ? 0 : 1) : 2
140+
})}
141+
pages={[
142+
[0, <p class="text-xl">String</p>],
143+
[1, <p class="text-xl">Bool</p>],
144+
[2, <p class="text-xl">None</p>],
145+
]}
146+
/>
147+
<InterfaceSwitch
148+
active={this.input2State.map(obj => {
149+
return obj.active ? (obj.type === InputStateType.String ? 0 : 1) : 2
150+
})}
151+
pages={[
152+
[0, <p class="text-xl">String</p>],
153+
[1, <p class="text-xl">Bool</p>],
154+
[2, <p class="text-xl">None</p>],
155+
]}
156+
/>
157+
</div>
158+
</div>
159+
<div class="w-2/3 bg-ng-background-700"></div>
160+
</div>
10161
</div>
11162
)
12163
}

0 commit comments

Comments
 (0)