Drone Config
This commit is contained in:
81
src/App.tsx
81
src/App.tsx
@@ -2,7 +2,14 @@ import { useState } from "react";
|
||||
import { resolveResource } from "@tauri-apps/api/path";
|
||||
import { readTextFile } from "@tauri-apps/api/fs";
|
||||
import { invoke } from '@tauri-apps/api/tauri'
|
||||
import Modal from "react-modal";
|
||||
import "./App.css";
|
||||
import { Command } from '@tauri-apps/api/shell'
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { faGitAlt } from "@fortawesome/free-brands-svg-icons/faGitAlt";
|
||||
|
||||
|
||||
// TODO: Keyboard usage
|
||||
|
||||
const codes = JSON.parse(await readTextFile(await resolveResource("resources/codes.json")));
|
||||
type Code = {
|
||||
@@ -11,13 +18,16 @@ type Code = {
|
||||
text: string;
|
||||
};
|
||||
|
||||
// TODO: Make Drone ID Dynamic
|
||||
// TODO: Make Drone ID configurable
|
||||
const droneId = 4661;
|
||||
Modal.setAppElement("#root");
|
||||
|
||||
function App() {
|
||||
|
||||
const [subTopic, setSubTopic] = useState<string>("");
|
||||
const [configModalOpen, setConfigModalOpen] = useState<boolean>(false);
|
||||
const [droneId, setDroneId] = useState<string>(() => {
|
||||
let storedId = localStorage.getItem("droneId");
|
||||
return (storedId ? storedId : "0000");
|
||||
});
|
||||
|
||||
const getSubjects = (input: Array<Code>) => {
|
||||
// TODO: Put all single-level elements at bottom
|
||||
@@ -43,7 +53,6 @@ function App() {
|
||||
};
|
||||
|
||||
const generatePayload = (code: Code) => {
|
||||
console.dir(code);
|
||||
let assembledStr: string = droneId.toString();
|
||||
let codeId: string = code.code.toString();
|
||||
if (code.code < 10) {
|
||||
@@ -76,12 +85,15 @@ function App() {
|
||||
} else {
|
||||
return (
|
||||
<div className="col-8 menu">
|
||||
{getTopicChildren(subTopic).map((text: string, index: number) => {
|
||||
{getTopicChildren(subTopic).map((text: string, index: number, topics: Array<string>) => {
|
||||
let displayText: string = text;
|
||||
displayText = displayText.replace(/.*:: /, "");
|
||||
if (displayText == "") {
|
||||
displayText = "...";
|
||||
}
|
||||
return(
|
||||
<div
|
||||
className="row sub-element"
|
||||
className={`row sub-element ${(topics.length-1 == index) ? "last" : ""}`}
|
||||
key={index}
|
||||
onClick={() => {
|
||||
handleSubClick(subTopic, index)
|
||||
@@ -110,6 +122,52 @@ function App() {
|
||||
|
||||
return (
|
||||
<div className="container">
|
||||
<Modal
|
||||
isOpen={configModalOpen}
|
||||
contentLabel="Configuration"
|
||||
overlayClassName="config-overlay"
|
||||
className="config-modal"
|
||||
>
|
||||
<div className="row">
|
||||
<h1 className="col-12">
|
||||
<a href="">Allen Wrench</a>
|
||||
</h1>
|
||||
</div>
|
||||
<div className="row">
|
||||
<h2 className="col-12">
|
||||
Hexcorp Drone Interface
|
||||
</h2>
|
||||
</div>
|
||||
<div className="row">
|
||||
<div className="col-6 text-end">
|
||||
Drone ID
|
||||
</div>
|
||||
<div className="col-6 drone-id-input">
|
||||
<input
|
||||
type="text"
|
||||
value={droneId}
|
||||
onChange={(e) => {
|
||||
setDroneId(e.target.value);
|
||||
localStorage.setItem("droneId", e.target.value);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="row modal-footer">
|
||||
<div className="col-4" onClick={() => {
|
||||
let url = "https://git.corrupt.link/liz/AllenWrench";
|
||||
// TODO: Make multi-platform
|
||||
new Command("open-link", ["-Command", "Start-Process", `${url}`]).spawn();
|
||||
}}>
|
||||
<FontAwesomeIcon className="icon" icon={faGitAlt} size="2x" />
|
||||
</div>
|
||||
<div className="col-8 text-end modal-close" onClick={() => {
|
||||
setConfigModalOpen(false);
|
||||
}}>
|
||||
Close
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
<div className="row">
|
||||
<div className="col-4">
|
||||
{getSubjects(codes).map((type: string, index: number) => {
|
||||
@@ -120,7 +178,7 @@ function App() {
|
||||
}
|
||||
return (
|
||||
<input
|
||||
className="item"
|
||||
className={`item ${(filtered.length == 1)?"individual":""}`}
|
||||
key={index}
|
||||
type="button"
|
||||
onClick={() => {
|
||||
@@ -134,9 +192,12 @@ function App() {
|
||||
<SubMenu/>
|
||||
</div>
|
||||
<div className="row footer">
|
||||
<div className="col-12 footer-content" onClick={()=>{setSubTopic("")}}>
|
||||
{/*TODO: Drone ID and Credits*/}
|
||||
4661
|
||||
<div className="col-12 footer-content" onClick={()=>{
|
||||
setSubTopic("");
|
||||
console.log(`Config modal open ${configModalOpen}`);
|
||||
setConfigModalOpen(!configModalOpen);
|
||||
}}>
|
||||
{droneId}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -22,12 +22,18 @@
|
||||
width: 100%;
|
||||
padding: 2px;
|
||||
border: 0px solid #ffffff00;
|
||||
border-bottom: 1px solid #d2b8eb3e;
|
||||
border-radius: 4px;
|
||||
margin-left: 4px;
|
||||
}
|
||||
|
||||
.sub-element:hover {
|
||||
background-color: #231929;
|
||||
color: #44B83D;
|
||||
}
|
||||
|
||||
.last {
|
||||
border-bottom: 0px solid #ffffff00;
|
||||
}
|
||||
|
||||
.menu {
|
||||
@@ -47,10 +53,14 @@
|
||||
color: #ffffff;
|
||||
background-color: #231929;
|
||||
}
|
||||
|
||||
.footer-content {
|
||||
z-index: 2;
|
||||
background-color: #231929;
|
||||
justify-content: end;
|
||||
text-align: right;
|
||||
cursor: pointer;
|
||||
color: #44B83D;
|
||||
font-family: 'Courier New', Courier, monospace;
|
||||
}
|
||||
|
||||
.item {
|
||||
@@ -67,6 +77,11 @@
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.individual {
|
||||
color: #44B83D;
|
||||
}
|
||||
|
||||
|
||||
.item:hover {
|
||||
background-color: #534264;
|
||||
}
|
||||
@@ -78,3 +93,85 @@
|
||||
h1 {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
a {
|
||||
text-decoration: none;
|
||||
color: #ffffff;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: #44B83D;
|
||||
}
|
||||
|
||||
.drone-id-input {
|
||||
margin-left: 0;
|
||||
padding-left: 0;
|
||||
}
|
||||
|
||||
.drone-id-input input{
|
||||
width: 50%;
|
||||
text-align: center;
|
||||
border: 0px solid #ffffff00;
|
||||
border-bottom: 1px solid #d2b8eb3e;
|
||||
border-radius: 4px;
|
||||
background-color: #231929;
|
||||
color: #ffffff;
|
||||
font-family: 'Courier New', Courier, monospace;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.modal-footer {
|
||||
position: absolute;
|
||||
bottom: 20px;
|
||||
left: 0;
|
||||
right: 0;
|
||||
padding-left: 20px;
|
||||
padding-right: 20px;
|
||||
}
|
||||
|
||||
h2 {
|
||||
text-align: center;
|
||||
font-family: 'Courier New', Courier, monospace;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.config-overlay {
|
||||
background-color: #23192967;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
.config-modal {
|
||||
position: absolute;
|
||||
top: 20px;
|
||||
left: 40px;
|
||||
right: 40px;
|
||||
bottom: 40px;
|
||||
padding: 18px;
|
||||
background-color: #382C44;
|
||||
color: #ffffff;
|
||||
filter: drop-shadow(0 0 0.2em #6f5887);
|
||||
border-radius: 20px;
|
||||
}
|
||||
|
||||
.modal-close {
|
||||
font-size: 24px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.modal-close:hover {
|
||||
color: #44B83D;
|
||||
}
|
||||
|
||||
.icon {
|
||||
color: #ffffff;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.icon:hover {
|
||||
color: #44B83D;
|
||||
}
|
||||
|
Reference in New Issue
Block a user