diff --git a/package.json b/package.json index 44d9e9f4..851123da 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,8 @@ "build": "tsc && vite build", "preview": "vite preview", "package": "gzipper c -i html,js,css,png,ico,svg,webmanifest,txt dist dist/output && tar -cvf dist/build.tar -C ./dist/output/ $(ls ./dist/output/)", - "format:check": "prettier --check . && eslint src/**/*.{ts,tsx}", - "format:fix": "prettier --write . && eslint --fix src/**/*.{ts,tsx}", + "format:check": "prettier --check . && eslint", + "format:fix": "prettier --write . && eslint --fix", "check:unimported": "unimported" }, "repository": { @@ -27,7 +27,7 @@ "@heroicons/react": "^2.0.13", "@hookform/error-message": "^2.0.1", "@hookform/resolvers": "^2.9.10", - "@meshtastic/meshtasticjs": "^0.7.5", + "@meshtastic/meshtasticjs": "^0.9.1", "@tailwindcss/line-clamp": "^0.4.2", "@tailwindcss/typography": "^0.5.8", "@turf/turf": "^6.5.0", @@ -48,7 +48,6 @@ "react-hook-form": "^7.41.2", "react-hot-toast": "^2.4.0", "react-icons": "^4.7.1", - "react-json-pretty": "^2.2.0", "react-json-tree": "^0.17.0", "react-map-gl": "^7.0.20", "react-qrcode-logo": "^2.8.0", @@ -78,7 +77,7 @@ "postcss": "^8.4.20", "prettier": "^2.8.1", "prettier-plugin-tailwindcss": "^0.2.1", - "rollup-plugin-visualizer": "^5.8.3", + "rollup-plugin-visualizer": "^5.9.0", "tailwindcss": "^3.2.4", "tar": "^6.1.13", "tslib": "^2.4.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c8fc0c0c..3bc127d8 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,7 +6,7 @@ specifiers: '@heroicons/react': ^2.0.13 '@hookform/error-message': ^2.0.1 '@hookform/resolvers': ^2.9.10 - '@meshtastic/meshtasticjs': ^0.7.5 + '@meshtastic/meshtasticjs': ^0.9.1 '@tailwindcss/forms': ^0.5.3 '@tailwindcss/line-clamp': ^0.4.2 '@tailwindcss/typography': ^0.5.8 @@ -49,12 +49,11 @@ specifiers: react-hook-form: ^7.41.2 react-hot-toast: ^2.4.0 react-icons: ^4.7.1 - react-json-pretty: ^2.2.0 react-json-tree: ^0.17.0 react-map-gl: ^7.0.20 react-qrcode-logo: ^2.8.0 rfc4648: ^1.5.2 - rollup-plugin-visualizer: ^5.8.3 + rollup-plugin-visualizer: ^5.9.0 tailwindcss: ^3.2.4 tar: ^6.1.13 tslib: ^2.4.1 @@ -71,7 +70,7 @@ dependencies: '@heroicons/react': 2.0.13_react@18.2.0 '@hookform/error-message': 2.0.1_33unso2ocv5y5ix74fsplqd6ny '@hookform/resolvers': 2.9.10_react-hook-form@7.41.2 - '@meshtastic/meshtasticjs': 0.7.5 + '@meshtastic/meshtasticjs': 0.9.1 '@tailwindcss/line-clamp': 0.4.2_tailwindcss@3.2.4 '@tailwindcss/typography': 0.5.8_tailwindcss@3.2.4 '@turf/turf': 6.5.0 @@ -92,7 +91,6 @@ dependencies: react-hook-form: 7.41.2_react@18.2.0 react-hot-toast: 2.4.0_biqbaboplfbrettd7655fr4n2y react-icons: 4.7.1_react@18.2.0 - react-json-pretty: 2.2.0_biqbaboplfbrettd7655fr4n2y react-json-tree: 0.17.0_kzbn2opkn2327fwg5yzwzya5o4 react-map-gl: 7.0.20_6eczaga5xxiwzxtfiyk6fioasq react-qrcode-logo: 2.8.0_biqbaboplfbrettd7655fr4n2y @@ -122,7 +120,7 @@ devDependencies: postcss: 8.4.20 prettier: 2.8.1 prettier-plugin-tailwindcss: 0.2.1_prettier@2.8.1 - rollup-plugin-visualizer: 5.8.3 + rollup-plugin-visualizer: 5.9.0 tailwindcss: 3.2.4_postcss@8.4.20 tar: 6.1.13 tslib: 2.4.1 @@ -1252,7 +1250,7 @@ packages: babel-plugin-polyfill-corejs2: 0.3.3_@babel+core@7.20.7 babel-plugin-polyfill-corejs3: 0.6.0_@babel+core@7.20.7 babel-plugin-polyfill-regenerator: 0.4.1_@babel+core@7.20.7 - core-js-compat: 3.27.0 + core-js-compat: 3.27.1 semver: 6.3.0 transitivePeerDependencies: - supports-color @@ -1712,8 +1710,8 @@ packages: engines: {node: '>=6.0.0'} dev: false - /@meshtastic/meshtasticjs/0.7.5: - resolution: {integrity: sha512-t4Yk/uf84WI3oia+ktZy35hlBZXKVQHm2suqGIlwewl6eFcRqi0dYHzSVugyYqs4vjOEmT5vZVpy9UZbyb/DTQ==} + /@meshtastic/meshtasticjs/0.9.1: + resolution: {integrity: sha512-BYTqcH/ArIr82EpYW23Y2cwvkWoKgNJAdjU21L8SUt9HjuVUNzeJOxieASINqLEWLFbcnOf7G5owmN2rKCSkLA==} dependencies: '@protobuf-ts/runtime': 2.8.2 glob: 8.0.3 @@ -3386,7 +3384,7 @@ packages: dependencies: '@babel/core': 7.20.7 '@babel/helper-define-polyfill-provider': 0.3.3_@babel+core@7.20.7 - core-js-compat: 3.27.0 + core-js-compat: 3.27.1 transitivePeerDependencies: - supports-color dev: true @@ -3653,8 +3651,8 @@ packages: resolution: {integrity: sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==} dev: true - /core-js-compat/3.27.0: - resolution: {integrity: sha512-spN2H4E/wocMML7XtbKuqttHHM+zbF3bAdl9mT4/iyFaF33bowQGjxiWNWyvUJGH9F+hTgnhWziiLtwu3oC/Qg==} + /core-js-compat/3.27.1: + resolution: {integrity: sha512-Dg91JFeCDA17FKnneN7oCMz4BkQ4TcffkgHP4OWwp9yx3pi7ubqMDXXSacfNak1PQqjc95skyt+YBLHQJnkJwA==} dependencies: browserslist: 4.21.4 dev: true @@ -5755,17 +5753,6 @@ packages: /react-is/16.13.1: resolution: {integrity: sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==} - /react-json-pretty/2.2.0_biqbaboplfbrettd7655fr4n2y: - resolution: {integrity: sha512-3UMzlAXkJ4R8S4vmkRKtvJHTewG4/rn1Q18n0zqdu/ipZbUPLVZD+QwC7uVcD/IAY3s8iNVHlgR2dMzIUS0n1A==} - peerDependencies: - react: '>=15.0' - react-dom: '>=15.0' - dependencies: - prop-types: 15.8.1 - react: 18.2.0 - react-dom: 18.2.0_react@18.2.0 - dev: false - /react-json-tree/0.17.0_kzbn2opkn2327fwg5yzwzya5o4: resolution: {integrity: sha512-hcWjibI/fAvsKnfYk+lka5OrE1Lvb1jH5pSnFhIU5T8cCCxB85r6h/NOzDPggSSgErjmx4rl3+2EkeclIKBOhg==} peerDependencies: @@ -6010,8 +5997,8 @@ packages: terser: 5.16.1 dev: true - /rollup-plugin-visualizer/5.8.3: - resolution: {integrity: sha512-QGJk4Bqe4AOat5AjipOh8esZH1nck5X2KFpf4VytUdSUuuuSwvIQZjMGgjcxe/zXexltqaXp5Vx1V3LmnQH15Q==} + /rollup-plugin-visualizer/5.9.0: + resolution: {integrity: sha512-bbDOv47+Bw4C/cgs0czZqfm8L82xOZssk4ayZjG40y9zbXclNk7YikrZTDao6p7+HDiGxrN0b65SgZiVm9k1Cg==} engines: {node: '>=14'} hasBin: true peerDependencies: @@ -6021,6 +6008,7 @@ packages: optional: true dependencies: open: 8.4.0 + picomatch: 2.3.1 source-map: 0.7.4 yargs: 17.6.2 dev: true diff --git a/src/components/CommandPalette/Index.tsx b/src/components/CommandPalette/Index.tsx index 21786236..a3978c34 100644 --- a/src/components/CommandPalette/Index.tsx +++ b/src/components/CommandPalette/Index.tsx @@ -214,7 +214,7 @@ export const CommandPalette = (): JSX.Element => { icon: TrashIcon, action() { if (connection) { - void toast.promise(connection.resetPeers({}), { + void toast.promise(connection.resetPeers(), { loading: "Resetting...", success: "Succesfully reset peers", error: "No response received" diff --git a/src/components/Dialog/RebootDialog.tsx b/src/components/Dialog/RebootDialog.tsx index 8c4781c4..a1a2449a 100644 --- a/src/components/Dialog/RebootDialog.tsx +++ b/src/components/Dialog/RebootDialog.tsx @@ -36,13 +36,11 @@ export const RebootDialog = ({ action={{ icon: , action() { - connection?.reboot({ - time: time * 60, - callback: async () => { - setRebootDialogOpen(false); - await Promise.resolve(); - } - }); + connection + ?.reboot({ + time: time * 60 + }) + .then(() => setRebootDialogOpen(false)); } }} /> @@ -50,13 +48,11 @@ export const RebootDialog = ({ className="w-24" iconBefore={} onClick={() => { - connection?.reboot({ - time: 0, - callback: async () => { - setRebootDialogOpen(false); - await Promise.resolve(); - } - }); + connection + ?.reboot({ + time: 0 + }) + .then(() => setRebootDialogOpen(false)); }} > Now diff --git a/src/components/Dialog/ShutdownDialog.tsx b/src/components/Dialog/ShutdownDialog.tsx index 8e60233b..d6db3dbd 100644 --- a/src/components/Dialog/ShutdownDialog.tsx +++ b/src/components/Dialog/ShutdownDialog.tsx @@ -36,13 +36,11 @@ export const ShutdownDialog = ({ action={{ icon: , action() { - connection?.shutdown({ - time: time * 60, - callback: async () => { - setShutdownDialogOpen(false); - await Promise.resolve(); - } - }); + connection + ?.shutdown({ + time: time * 60 + }) + .then(() => setShutdownDialogOpen(false)); } }} /> @@ -50,13 +48,11 @@ export const ShutdownDialog = ({ className="w-24" iconBefore={} onClick={() => { - connection?.shutdown({ - time: 0, - callback: async () => { - setShutdownDialogOpen(false); - await Promise.resolve(); - } - }); + connection + ?.shutdown({ + time: 0 + }) + .then(() => setShutdownDialogOpen(false)); }} > Now diff --git a/src/components/PageComponents/Channel.tsx b/src/components/PageComponents/Channel.tsx index f8fc389e..6ea9124e 100644 --- a/src/components/PageComponents/Channel.tsx +++ b/src/components/PageComponents/Channel.tsx @@ -65,25 +65,23 @@ export const Channel = ({ channel }: SettingsPanelProps): JSX.Element => { const onSubmit = handleSubmit((data) => { if (connection) { void toast.promise( - connection.setChannel({ - channel: { - role: - channel?.role === Protobuf.Channel_Role.PRIMARY - ? Protobuf.Channel_Role.PRIMARY - : data.enabled - ? Protobuf.Channel_Role.SECONDARY - : Protobuf.Channel_Role.DISABLED, - index: channel?.index, - settings: { - ...data, - psk: toByteArray(data.psk ?? "") + connection + .setChannel({ + channel: { + role: + channel?.role === Protobuf.Channel_Role.PRIMARY + ? Protobuf.Channel_Role.PRIMARY + : data.enabled + ? Protobuf.Channel_Role.SECONDARY + : Protobuf.Channel_Role.DISABLED, + index: channel?.index, + settings: { + ...data, + psk: toByteArray(data.psk ?? "") + } } - }, - callback: (): Promise => { - reset({ ...data }); - return Promise.resolve(); - } - }), + }) + .then(() => reset({ ...data })), { loading: "Saving...", success: "Saved Channel", diff --git a/src/components/PageComponents/Config/Bluetooth.tsx b/src/components/PageComponents/Config/Bluetooth.tsx index 7250fc41..3909bfcd 100644 --- a/src/components/PageComponents/Config/Bluetooth.tsx +++ b/src/components/PageComponents/Config/Bluetooth.tsx @@ -35,18 +35,16 @@ export const Bluetooth = (): JSX.Element => { const onSubmit = handleSubmit((data) => { if (connection) { void toast.promise( - connection.setConfig({ - config: { - payloadVariant: { - oneofKind: "bluetooth", - bluetooth: data + connection + .setConfig({ + config: { + payloadVariant: { + oneofKind: "bluetooth", + bluetooth: data + } } - }, - callback: async () => { - reset({ ...data }); - await Promise.resolve(); - } - }), + }) + .then(() => reset({ ...data })), { loading: "Saving...", success: "Saved Bluetooth Config, Restarting Node", diff --git a/src/components/PageComponents/Config/Device.tsx b/src/components/PageComponents/Config/Device.tsx index 7ad664a3..fbadf56c 100644 --- a/src/components/PageComponents/Config/Device.tsx +++ b/src/components/PageComponents/Config/Device.tsx @@ -34,18 +34,16 @@ export const Device = (): JSX.Element => { const onSubmit = handleSubmit((data) => { if (connection) { void toast.promise( - connection.setConfig({ - config: { - payloadVariant: { - oneofKind: "device", - device: data + connection + .setConfig({ + config: { + payloadVariant: { + oneofKind: "device", + device: data + } } - }, - callback: async () => { - reset({ ...data }); - await Promise.resolve(); - } - }), + }) + .then(() => reset({ ...data })), { loading: "Saving...", success: "Saved Device Config, Restarting Node", diff --git a/src/components/PageComponents/Config/Display.tsx b/src/components/PageComponents/Config/Display.tsx index 97a81a9c..916c9ed1 100644 --- a/src/components/PageComponents/Config/Display.tsx +++ b/src/components/PageComponents/Config/Display.tsx @@ -34,18 +34,16 @@ export const Display = (): JSX.Element => { const onSubmit = handleSubmit((data) => { if (connection) { void toast.promise( - connection.setConfig({ - config: { - payloadVariant: { - oneofKind: "display", - display: data + connection + .setConfig({ + config: { + payloadVariant: { + oneofKind: "display", + display: data + } } - }, - callback: async () => { - reset({ ...data }); - await Promise.resolve(); - } - }), + }) + .then(() => reset({ ...data })), { loading: "Saving...", success: "Saved Display Config, Restarting Node", diff --git a/src/components/PageComponents/Config/LoRa.tsx b/src/components/PageComponents/Config/LoRa.tsx index a1cf8e4c..252da69c 100644 --- a/src/components/PageComponents/Config/LoRa.tsx +++ b/src/components/PageComponents/Config/LoRa.tsx @@ -42,18 +42,16 @@ export const LoRa = (): JSX.Element => { const onSubmit = handleSubmit((data) => { if (connection) { void toast.promise( - connection.setConfig({ - config: { - payloadVariant: { - oneofKind: "lora", - lora: data + connection + .setConfig({ + config: { + payloadVariant: { + oneofKind: "lora", + lora: data + } } - }, - callback: async () => { - reset({ ...data }); - await Promise.resolve(); - } - }), + }) + .then(() => reset({ ...data })), { loading: "Saving...", success: "Saved LoRa Config, Restarting Node", diff --git a/src/components/PageComponents/Config/Network.tsx b/src/components/PageComponents/Config/Network.tsx index be9297bc..c07bae22 100644 --- a/src/components/PageComponents/Config/Network.tsx +++ b/src/components/PageComponents/Config/Network.tsx @@ -63,13 +63,9 @@ export const Network = (): JSX.Element => { oneofKind: "network", network: Protobuf.Config_NetworkConfig.create(data) } - }, - callback: async () => { - reset({ ...data }); - await Promise.resolve(); } }) - .catch((e) => console.log(e)), + .then(() => reset({ ...data })), { loading: "Saving...", success: "Saved Network Config, Restarting Node", diff --git a/src/components/PageComponents/Config/Position.tsx b/src/components/PageComponents/Config/Position.tsx index 5fee0256..6f2917e9 100644 --- a/src/components/PageComponents/Config/Position.tsx +++ b/src/components/PageComponents/Config/Position.tsx @@ -60,17 +60,15 @@ export const Position = (): JSX.Element => { if (connection) { void toast.promise( - connection.setPosition({ - position: Protobuf.Position.create({ - altitude: fixedAlt, - latitudeI: fixedLat * 1e7, - longitudeI: fixedLng * 1e7 - }), - callback: async () => { - reset({ ...data }); - await Promise.resolve(); - } - }), + connection + .setPosition({ + position: Protobuf.Position.create({ + altitude: fixedAlt, + latitudeI: fixedLat * 1e7, + longitudeI: fixedLng * 1e7 + }) + }) + .then(() => reset({ ...data })), { loading: "Saving...", success: "Saved Position Config, Restarting Node", @@ -79,18 +77,16 @@ export const Position = (): JSX.Element => { ); if (configHasChanged) { void toast.promise( - connection.setConfig({ - config: { - payloadVariant: { - oneofKind: "position", - position: rest + connection + .setConfig({ + config: { + payloadVariant: { + oneofKind: "position", + position: rest + } } - }, - callback: async () => { - reset({ ...data }); - await Promise.resolve(); - } - }), + }) + .then(() => reset({ ...data })), { loading: "Saving...", success: "Saved Position Config, Restarting Node", diff --git a/src/components/PageComponents/Config/Power.tsx b/src/components/PageComponents/Config/Power.tsx index 8a859b67..4b1928e6 100644 --- a/src/components/PageComponents/Config/Power.tsx +++ b/src/components/PageComponents/Config/Power.tsx @@ -32,18 +32,16 @@ export const Power = (): JSX.Element => { const onSubmit = handleSubmit((data) => { if (connection) { void toast.promise( - connection.setConfig({ - config: { - payloadVariant: { - oneofKind: "power", - power: data + connection + .setConfig({ + config: { + payloadVariant: { + oneofKind: "power", + power: data + } } - }, - callback: async () => { - reset({ ...data }); - await Promise.resolve(); - } - }), + }) + .then(() => reset({ ...data })), { loading: "Saving...", success: "Saved Power Config, Restarting Node", diff --git a/src/components/PageComponents/Config/User.tsx b/src/components/PageComponents/Config/User.tsx index 2e421076..81e15fe6 100644 --- a/src/components/PageComponents/Config/User.tsx +++ b/src/components/PageComponents/Config/User.tsx @@ -42,13 +42,11 @@ export const User = (): JSX.Element => { const onSubmit = handleSubmit((data) => { if (connection && myNode?.data.user) { void toast.promise( - connection.setOwner({ - owner: { ...myNode.data.user, ...data }, - callback: async () => { - reset({ ...data }); - await Promise.resolve(); - } - }), + connection + .setOwner({ + owner: { ...myNode.data.user, ...data } + }) + .then(() => reset({ ...data })), { loading: "Saving...", success: "Saved User, Restarting Node", diff --git a/src/components/PageComponents/Messages/Message.tsx b/src/components/PageComponents/Messages/Message.tsx index 2a43a142..3b8857d2 100644 --- a/src/components/PageComponents/Messages/Message.tsx +++ b/src/components/PageComponents/Messages/Message.tsx @@ -31,17 +31,19 @@ export const Message = ({ return lastMsgSameUser ? (
- {message.ack ? ( + {message.state === "ack" ? ( - ) : ( + ) : message.state === "waiting" ? ( + ) : ( + )} {"waypointID" in message ? ( ) : ( {message.text} @@ -69,17 +71,21 @@ export const Message = ({
{/* */} - {message.ack ? ( + {message.state === "ack" ? ( - ) : ( + ) : message.state === "waiting" ? ( + ) : ( + )} {"waypointID" in message ? ( ) : ( {message.text} diff --git a/src/components/PageComponents/Messages/MessageInput.tsx b/src/components/PageComponents/Messages/MessageInput.tsx index f8ebea7d..f2864c27 100644 --- a/src/components/PageComponents/Messages/MessageInput.tsx +++ b/src/components/PageComponents/Messages/MessageInput.tsx @@ -14,7 +14,7 @@ export interface MessageInputProps { } export const MessageInput = ({ channel }: MessageInputProps): JSX.Element => { - const { connection, ackMessage } = useDevice(); + const { connection, setMessageState } = useDevice(); const { register, handleSubmit } = useForm<{ message: string; @@ -24,16 +24,17 @@ export const MessageInput = ({ channel }: MessageInputProps): JSX.Element => { } }); - const onSubmit = handleSubmit((data) => { - void connection?.sendText({ - text: data.message, - wantAck: true, - channel: channel.config.index as Types.ChannelNumber, - callback: (id) => { - ackMessage(channel.config.index, id); - return Promise.resolve(); - } - }); + const onSubmit = handleSubmit(async (data) => { + await connection + ?.sendText({ + text: data.message, + wantAck: true, + channel: channel.config.index as Types.ChannelNumber + }) + .then((id) => setMessageState(channel.config.index, id, "ack")) + .catch((e: Types.PacketError) => + setMessageState(channel.config.index, e.id, e.error) + ); }); return ( diff --git a/src/components/PageComponents/ModuleConfig/CannedMessage.tsx b/src/components/PageComponents/ModuleConfig/CannedMessage.tsx index cd22a6b5..e033d2a1 100644 --- a/src/components/PageComponents/ModuleConfig/CannedMessage.tsx +++ b/src/components/PageComponents/ModuleConfig/CannedMessage.tsx @@ -40,18 +40,16 @@ export const CannedMessage = (): JSX.Element => { const onSubmit = handleSubmit((data) => { if (connection) { void toast.promise( - connection.setModuleConfig({ - moduleConfig: { - payloadVariant: { - oneofKind: "cannedMessage", - cannedMessage: data + connection + .setModuleConfig({ + moduleConfig: { + payloadVariant: { + oneofKind: "cannedMessage", + cannedMessage: data + } } - }, - callback: async () => { - reset({ ...data }); - await Promise.resolve(); - } - }), + }) + .then(() => reset({ ...data })), { loading: "Saving...", success: "Saved Canned Message Config, Restarting Node", diff --git a/src/components/PageComponents/ModuleConfig/ExternalNotification.tsx b/src/components/PageComponents/ModuleConfig/ExternalNotification.tsx index 9dff6f86..516eb7f3 100644 --- a/src/components/PageComponents/ModuleConfig/ExternalNotification.tsx +++ b/src/components/PageComponents/ModuleConfig/ExternalNotification.tsx @@ -30,18 +30,16 @@ export const ExternalNotification = (): JSX.Element => { const onSubmit = handleSubmit((data) => { if (connection) { void toast.promise( - connection.setModuleConfig({ - moduleConfig: { - payloadVariant: { - oneofKind: "externalNotification", - externalNotification: data + connection + .setModuleConfig({ + moduleConfig: { + payloadVariant: { + oneofKind: "externalNotification", + externalNotification: data + } } - }, - callback: async () => { - reset({ ...data }); - await Promise.resolve(); - } - }), + }) + .then(() => reset({ ...data })), { loading: "Saving...", success: "Saved External Notification Config, Restarting Node", diff --git a/src/components/PageComponents/ModuleConfig/MQTT.tsx b/src/components/PageComponents/ModuleConfig/MQTT.tsx index 9df15873..435ee7f1 100644 --- a/src/components/PageComponents/ModuleConfig/MQTT.tsx +++ b/src/components/PageComponents/ModuleConfig/MQTT.tsx @@ -37,18 +37,16 @@ export const MQTT = (): JSX.Element => { const onSubmit = handleSubmit((data) => { if (connection) { void toast.promise( - connection.setModuleConfig({ - moduleConfig: { - payloadVariant: { - oneofKind: "mqtt", - mqtt: data + connection + .setModuleConfig({ + moduleConfig: { + payloadVariant: { + oneofKind: "mqtt", + mqtt: data + } } - }, - callback: async () => { - reset({ ...data }); - await Promise.resolve(); - } - }), + }) + .then(() => reset({ ...data })), { loading: "Saving...", success: "Saved MQTT Config, Restarting Node", diff --git a/src/components/PageComponents/ModuleConfig/RangeTest.tsx b/src/components/PageComponents/ModuleConfig/RangeTest.tsx index 89773231..11664218 100644 --- a/src/components/PageComponents/ModuleConfig/RangeTest.tsx +++ b/src/components/PageComponents/ModuleConfig/RangeTest.tsx @@ -31,18 +31,16 @@ export const RangeTest = (): JSX.Element => { const onSubmit = handleSubmit((data) => { if (connection) { void toast.promise( - connection.setModuleConfig({ - moduleConfig: { - payloadVariant: { - oneofKind: "rangeTest", - rangeTest: data + connection + .setModuleConfig({ + moduleConfig: { + payloadVariant: { + oneofKind: "rangeTest", + rangeTest: data + } } - }, - callback: async () => { - reset({ ...data }); - await Promise.resolve(); - } - }), + }) + .then(() => reset({ ...data })), { loading: "Saving...", success: "Saved Range Test Config, Restarting Node", diff --git a/src/components/PageComponents/ModuleConfig/Serial.tsx b/src/components/PageComponents/ModuleConfig/Serial.tsx index 4a62e4f4..01aac75c 100644 --- a/src/components/PageComponents/ModuleConfig/Serial.tsx +++ b/src/components/PageComponents/ModuleConfig/Serial.tsx @@ -31,18 +31,16 @@ export const Serial = (): JSX.Element => { const onSubmit = handleSubmit((data) => { if (connection) { void toast.promise( - connection.setModuleConfig({ - moduleConfig: { - payloadVariant: { - oneofKind: "serial", - serial: data + connection + .setModuleConfig({ + moduleConfig: { + payloadVariant: { + oneofKind: "serial", + serial: data + } } - }, - callback: async () => { - reset({ ...data }); - await Promise.resolve(); - } - }), + }) + .then(() => reset({ ...data })), { loading: "Saving...", success: "Saved Serial Config, Restarting Node", diff --git a/src/components/PageComponents/ModuleConfig/StoreForward.tsx b/src/components/PageComponents/ModuleConfig/StoreForward.tsx index 2b5f9b77..e52e31ec 100644 --- a/src/components/PageComponents/ModuleConfig/StoreForward.tsx +++ b/src/components/PageComponents/ModuleConfig/StoreForward.tsx @@ -31,18 +31,16 @@ export const StoreForward = (): JSX.Element => { const onSubmit = handleSubmit((data) => { if (connection) { void toast.promise( - connection.setModuleConfig({ - moduleConfig: { - payloadVariant: { - oneofKind: "storeForward", - storeForward: data + connection + .setModuleConfig({ + moduleConfig: { + payloadVariant: { + oneofKind: "storeForward", + storeForward: data + } } - }, - callback: async () => { - reset({ ...data }); - await Promise.resolve(); - } - }), + }) + .then(() => reset({ ...data })), { loading: "Saving...", success: "Saved Store & Forward Config, Restarting Node", diff --git a/src/components/PageComponents/ModuleConfig/Telemetry.tsx b/src/components/PageComponents/ModuleConfig/Telemetry.tsx index 84147db9..cb9014cb 100644 --- a/src/components/PageComponents/ModuleConfig/Telemetry.tsx +++ b/src/components/PageComponents/ModuleConfig/Telemetry.tsx @@ -31,18 +31,19 @@ export const Telemetry = (): JSX.Element => { const onSubmit = handleSubmit((data) => { if (connection) { void toast.promise( - connection.setModuleConfig({ - moduleConfig: { - payloadVariant: { - oneofKind: "telemetry", - telemetry: data + connection + .setModuleConfig({ + moduleConfig: { + payloadVariant: { + oneofKind: "telemetry", + telemetry: data + } } - }, - callback: async () => { + }) + .then(async () => { reset({ ...data }); await Promise.resolve(); - } - }), + }), { loading: "Saving...", success: "Saved Telemetry Config, Restarting Node", diff --git a/src/core/stores/deviceStore.ts b/src/core/stores/deviceStore.ts index 09cd5f57..2a13348a 100644 --- a/src/core/stores/deviceStore.ts +++ b/src/core/stores/deviceStore.ts @@ -15,16 +15,19 @@ export type Page = | "info" | "logs"; -export interface MessageWithAck extends Types.MessagePacket { - ack: boolean; +export interface MessageWithState extends Types.MessagePacket { + state: MessageState; } -export interface WaypointIDWithAck extends Omit { +export interface WaypointIDWithState + extends Omit { waypointID: number; - ack: boolean; + state: MessageState; } -export type AllMessageTypes = MessageWithAck | WaypointIDWithAck; +export type AllMessageTypes = MessageWithState | WaypointIDWithState; + +export type MessageState = "ack" | "waiting" | Protobuf.Routing_Error; export interface Channel { config: Protobuf.Channel; @@ -77,10 +80,14 @@ export interface Device { addUser: (user: Types.UserPacket) => void; addPosition: (position: Types.PositionPacket) => void; addConnection: (connection: Types.ConnectionType) => void; - addMessage: (message: MessageWithAck) => void; - addWaypointMessage: (message: WaypointIDWithAck) => void; + addMessage: (message: MessageWithState) => void; + addWaypointMessage: (message: WaypointIDWithState) => void; addDeviceMetadataMessage: (metadata: Types.DeviceMetadataPacket) => void; - ackMessage: (channelIndex: number, messageId: number) => void; + setMessageState: ( + channelIndex: number, + messageId: number, + state: MessageState + ) => void; setImportDialogOpen: (open: boolean) => void; setQRDialogOpen: (open: boolean) => void; setShutdownDialogOpen: (open: boolean) => void; @@ -517,7 +524,11 @@ export const useDeviceStore = create((set, get) => ({ }) ); }, - ackMessage: (channelIndex: number, messageId: number) => { + setMessageState: ( + channelIndex: number, + messageId: number, + state: MessageState + ) => { set( produce((draft) => { const device = draft.devices.get(id); @@ -529,7 +540,7 @@ export const useDeviceStore = create((set, get) => ({ (msg) => msg.packet.id === messageId ); if (message) { - message.ack = true; + message.state = state; } }) ); diff --git a/src/core/subscriptions.ts b/src/core/subscriptions.ts index 16fa478e..36964d59 100644 --- a/src/core/subscriptions.ts +++ b/src/core/subscriptions.ts @@ -65,7 +65,7 @@ export const subscribeAll = ( device.addWaypoint(data); device.addWaypointMessage({ waypointID: data.id, - ack: rest.packet.from !== myNodeNum, + state: rest.packet.from !== myNodeNum ? "ack" : "waiting", ...rest }); }); @@ -107,7 +107,7 @@ export const subscribeAll = ( connection.events.onMessagePacket.subscribe((messagePacket) => { device.addMessage({ ...messagePacket, - ack: messagePacket.packet.from !== myNodeNum + state: messagePacket.packet.from !== myNodeNum ? "ack" : "waiting" }); }); diff --git a/vite.config.ts b/vite.config.ts index 5cfc750e..a9e641b8 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -20,13 +20,13 @@ export default defineConfig({ react(), EnvironmentPlugin({ COMMIT_HASH: hash - }), - VitePWA({ - registerType: "autoUpdate", - devOptions: { - enabled: true - } }) + // VitePWA({ + // registerType: "autoUpdate", + // devOptions: { + // enabled: true + // } + // }) ], build: { target: "esnext",