diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 1305d46..07bca99 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -8,7 +8,7 @@ }, "package": { "productName": "allenwrench-app", - "version": "0.1.0" + "version": "0.1.1" }, "tauri": { "allowlist": { diff --git a/src/App.tsx b/src/App.tsx index 8d0cad5..7e73d53 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -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>(); const [subTopic, setSubTopic] = useState(""); const [configModalOpen, setConfigModalOpen] = useState(false); const [droneId, setDroneId] = useState(() => { @@ -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) => { // TODO: Put all single-level elements at bottom let subjects: Array = []; @@ -53,13 +63,15 @@ function App() { const getTopicChildren = (topic: string) => { let topicChildren: Array = []; - 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 ( +
+ {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 ( + { + handleTopicClick(type) + }} + value={dispType} + /> + ); + })} +
+ ); + // TODO: This isn't returning as expected, use an object to append to then return the compiled list + }else{ + return (
); + } + }; + return (
- {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 ( - { - handleTopicClick(type) - }} - value={dispType} - /> - ); - })} + {buildMenu()}