Await incompatibility fix

This commit is contained in:
Elizabeth Cray 2023-07-23 20:36:14 -04:00
parent 768bc82c5b
commit 454108a959
2 changed files with 51 additions and 26 deletions

View File

@ -8,7 +8,7 @@
},
"package": {
"productName": "allenwrench-app",
"version": "0.1.0"
"version": "0.1.1"
},
"tauri": {
"allowlist": {

View File

@ -12,7 +12,10 @@ import { PhysicalPosition, appWindow } from "@tauri-apps/api/window";
// TODO: Keyboard usage
const codes = JSON.parse(await readTextFile(await resolveResource("resources/codes.json")));
// const codes = JSON.parse(await readTextFile(await resolveResource("resources/codes.json")));
type Code = {
code: number;
type: string;
@ -33,6 +36,7 @@ invoke('get_mouse_pos', {}).then((posJson: any) => {
Modal.setAppElement("#root");
function App() {
const [codes, setCodes] = useState<Array<Code>>();
const [subTopic, setSubTopic] = useState<string>("");
const [configModalOpen, setConfigModalOpen] = useState<boolean>(false);
const [droneId, setDroneId] = useState<string>(() => {
@ -40,6 +44,12 @@ function App() {
return (storedId ? storedId : "0000");
});
resolveResource("resources/codes.json").then((path: string) => {
readTextFile(path).then((codesJson: string) => {
setCodes(JSON.parse(codesJson));
});
});
const getSubjects = (input: Array<Code>) => {
// TODO: Put all single-level elements at bottom
let subjects: Array<string> = [];
@ -53,13 +63,15 @@ function App() {
const getTopicChildren = (topic: string) => {
let topicChildren: Array<string> = [];
codes.forEach((code: Code) => {
if (code.type == topic) {
if (!topicChildren.includes(code.text)) {
topicChildren.push(code.text)
if (codes){
codes.forEach((code: Code) => {
if (code.type == topic) {
if (!topicChildren.includes(code.text)) {
topicChildren.push(code.text)
}
}
}
});
});
}
return topicChildren;
};
@ -131,6 +143,36 @@ function App() {
}
};
const buildMenu = () => {
if (codes) {
return (
<div>
{getSubjects(codes).map((type: string, index: number) => {
let dispType: string = type;
let filtered = codes.filter((code: Code) => code.type === type);
if (filtered.length == 1) {
dispType += ((filtered[0].text == "")?" :: ...":((filtered[0].text == ".")?"":(" :: "+filtered[0].text)));
}
return (
<input
className={`item ${(filtered.length == 1)?"individual":""}`}
key={index}
type="button"
onClick={() => {
handleTopicClick(type)
}}
value={dispType}
/>
);
})}
</div>
);
// TODO: This isn't returning as expected, use an object to append to then return the compiled list
}else{
return (<div></div>);
}
};
return (
<div className="container">
<Modal
@ -198,24 +240,7 @@ function App() {
</Modal>
<div className="row">
<div className="col-4">
{getSubjects(codes).map((type: string, index: number) => {
let dispType: string = type;
let filtered = codes.filter((code: Code) => code.type === type);
if (filtered.length == 1) {
dispType += ((filtered[0].text == "")?" :: ...":((filtered[0].text == ".")?"":(" :: "+filtered[0].text)));
}
return (
<input
className={`item ${(filtered.length == 1)?"individual":""}`}
key={index}
type="button"
onClick={() => {
handleTopicClick(type)
}}
value={dispType}
/>
);
})}
{buildMenu()}
</div>
<SubMenu/>
</div>