feat(mobile): update notifications and more error handling added
All checks were successful
Build and Push LST Docker Image / docker (push) Successful in 1m24s
All checks were successful
Build and Push LST Docker Image / docker (push) Successful in 1m24s
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import axios from "axios";
|
||||
import { format } from "date-fns-tz";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { Text, View } from "react-native";
|
||||
@@ -7,6 +8,8 @@ import { scannerFeedback } from "../lib/feedbackScan";
|
||||
import { sendTcpMessage } from "../lib/tcpScan";
|
||||
import { type ZebraScanResult, zebraScanner } from "../lib/ZebraScanner";
|
||||
import { ScannedLabelBox } from "./ScannedLabels";
|
||||
import { GlobalFooter } from "./UpdateFooter";
|
||||
import { Separator } from "./ui/separator";
|
||||
|
||||
const STX = "\x02";
|
||||
const ETX = "\x03";
|
||||
@@ -23,12 +26,6 @@ export default function ProdScanner() {
|
||||
const handleScan = useCallback(
|
||||
async (scan: ZebraScanResult) => {
|
||||
let commandToSend = `${STX}${scannerIdFromStore}@${scan.data}${ETX}`;
|
||||
await scannerFeedback({
|
||||
type: "good",
|
||||
sound: true,
|
||||
vibrate: true,
|
||||
led: true,
|
||||
});
|
||||
|
||||
// if we are sscc we need to scan like this .... <STX>98@]C100090087710038712256<ETX>
|
||||
if (scan.data.startsWith("000")) {
|
||||
@@ -42,41 +39,54 @@ export default function ProdScanner() {
|
||||
]);
|
||||
}
|
||||
|
||||
// if we change commands we want to zero out the last scanned labels
|
||||
if (/^[a-zA-Z]/.test(scan.data)) {
|
||||
setTagScans([]);
|
||||
}
|
||||
|
||||
const scanned = (await sendTcpMessage(
|
||||
commandToSend,
|
||||
serverIp,
|
||||
parseInt(serverPort || "0", 10),
|
||||
)) as any;
|
||||
// Later this is where your TCP send goes.
|
||||
// const response = await sendTcpMessage(tcpMessage);
|
||||
console.log(scanned);
|
||||
await scannerFeedback({
|
||||
type: scanned.data[0]?.type === "error" ? "bad" : "good",
|
||||
sound: true,
|
||||
vibrate: true,
|
||||
led: true,
|
||||
});
|
||||
// send the logs to lst but allow it to time out if it dose not exist just bc.
|
||||
|
||||
if (scanned.data[0]?.type !== "error") {
|
||||
try {
|
||||
await axios.post(
|
||||
`http://${serverIp.trim()}:3000/lst/api/mobile/logs`,
|
||||
scanned,
|
||||
);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
// const response = await sendTcpMessage(tcpMessage);
|
||||
console.log(scanned.data);
|
||||
if (scanned.data.status !== "error") {
|
||||
await scannerFeedback({
|
||||
type: "good",
|
||||
sound: true,
|
||||
vibrate: true,
|
||||
led: true,
|
||||
});
|
||||
setBGColor("bg-green-500");
|
||||
setTimeout(() => {
|
||||
setBGColor(null);
|
||||
}, 1 * 1000);
|
||||
}
|
||||
|
||||
if (scanned.data[0]?.type === "error") {
|
||||
if (scanned.data.status === "error") {
|
||||
await scannerFeedback({
|
||||
type: scanned.data.status === "error" ? "bad" : "good",
|
||||
sound: true,
|
||||
vibrate: true,
|
||||
led: true,
|
||||
});
|
||||
setBGColor("bg-red-500");
|
||||
setTimeout(() => {
|
||||
setBGColor(null);
|
||||
}, 1 * 1000);
|
||||
}
|
||||
setLastScan(scanned.data[0]);
|
||||
//console.log("TCP response:", something);
|
||||
setLastScan(scanned.data);
|
||||
|
||||
// if we change commands we want to zero out the last scanned labels
|
||||
if (/^[a-zA-Z]/.test(scan.data)) {
|
||||
setTagScans([]);
|
||||
}
|
||||
},
|
||||
[scannerIdFromStore, serverIp, serverPort, setLastScan],
|
||||
);
|
||||
@@ -85,7 +95,7 @@ export default function ProdScanner() {
|
||||
setTagScans([]);
|
||||
};
|
||||
|
||||
console.log(lastScan);
|
||||
//console.log(lastScan);
|
||||
|
||||
useEffect(() => {
|
||||
zebraScanner.ensureProfile();
|
||||
@@ -109,6 +119,7 @@ export default function ProdScanner() {
|
||||
Scanner ID: {parseInt(scannerIdFromStore || "0", 10)}
|
||||
</Text>
|
||||
</View>
|
||||
<Separator />
|
||||
{!lastScan ? (
|
||||
<View style={{ marginTop: 10, alignItems: "center" }}>
|
||||
<Text className="text-xl font-bold">Ready to scan</Text>
|
||||
@@ -121,18 +132,19 @@ export default function ProdScanner() {
|
||||
alignItems: "center",
|
||||
}}
|
||||
>
|
||||
<View style={{ marginTop: 10, alignItems: "center" }}>
|
||||
<Text style={{ fontSize: 20, fontWeight: "600" }}>
|
||||
{lastScan.action}
|
||||
</Text>
|
||||
|
||||
<Text style={{ fontSize: 20, fontWeight: "600" }}>
|
||||
{lastScan.message}
|
||||
</Text>
|
||||
</View>
|
||||
{lastScan.lines
|
||||
?.filter((line) => !/^\d+@$/.test(line))
|
||||
.map((i) => {
|
||||
return (
|
||||
<View style={{ marginTop: 10, alignItems: "center" }} key={i}>
|
||||
<Text style={{ fontSize: 20, fontWeight: "600" }}>{i}</Text>
|
||||
</View>
|
||||
);
|
||||
})}
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
<Separator className="m-2" />
|
||||
<View className="flex-1 w-full px-4">
|
||||
<ScannedLabelBox
|
||||
labels={tagScans}
|
||||
@@ -140,6 +152,9 @@ export default function ProdScanner() {
|
||||
clearScan={clearScans}
|
||||
/>
|
||||
</View>
|
||||
<View>
|
||||
<GlobalFooter />
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user