thêm quét QR đăng nhập, sửa lại logic để gọi api bằng ip thiết bị
This commit is contained in:
@@ -23,6 +23,8 @@ export default function ScanQRCode({
|
||||
const [permission, requestPermission] = useCameraPermissions();
|
||||
const [scanned, setScanned] = useState(false);
|
||||
const cameraRef = useRef(null);
|
||||
// Dùng ref để chặn quét nhiều lần trong cùng một frame/event loop
|
||||
const hasScannedRef = useRef(false);
|
||||
|
||||
// Request camera permission when component mounts or when visible changes to true
|
||||
useEffect(() => {
|
||||
@@ -38,6 +40,13 @@ export default function ScanQRCode({
|
||||
}
|
||||
}, [visible]);
|
||||
|
||||
// Mỗi khi reset scanned state thì reset luôn ref guard
|
||||
useEffect(() => {
|
||||
if (!scanned) {
|
||||
hasScannedRef.current = false;
|
||||
}
|
||||
}, [scanned]);
|
||||
|
||||
const handleBarCodeScanned = ({
|
||||
type,
|
||||
data,
|
||||
@@ -45,11 +54,12 @@ export default function ScanQRCode({
|
||||
type: string;
|
||||
data: string;
|
||||
}) => {
|
||||
if (!scanned) {
|
||||
setScanned(true);
|
||||
onScanned(data);
|
||||
onClose();
|
||||
}
|
||||
// Nếu đã scan rồi, bỏ qua
|
||||
if (hasScannedRef.current || scanned) return;
|
||||
hasScannedRef.current = true;
|
||||
setScanned(true);
|
||||
onScanned(data);
|
||||
onClose();
|
||||
};
|
||||
|
||||
if (!permission) {
|
||||
@@ -102,7 +112,8 @@ export default function ScanQRCode({
|
||||
<CameraView
|
||||
ref={cameraRef}
|
||||
style={styles.camera}
|
||||
onBarcodeScanned={handleBarCodeScanned}
|
||||
// Chỉ gắn handler khi chưa scan để ngắt lắng nghe ngay lập tức sau khi quét thành công
|
||||
onBarcodeScanned={scanned ? undefined : handleBarCodeScanned}
|
||||
barcodeScannerSettings={{
|
||||
barcodeTypes: ["qr"],
|
||||
}}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { showToastError } from "@/config";
|
||||
import {
|
||||
queryDeleteSos,
|
||||
queryGetSos,
|
||||
querySendSosMessage,
|
||||
} from "@/controller/DeviceController";
|
||||
import { showErrorToast } from "@/services/toast_service";
|
||||
import { sosMessage } from "@/utils/sosUtils";
|
||||
import { MaterialIcons } from "@expo/vector-icons";
|
||||
import { useEffect, useState } from "react";
|
||||
@@ -108,7 +108,7 @@ const SosButton = () => {
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error when send sos: ", error);
|
||||
showToastError("Không thể gửi tín hiệu SOS", "Lỗi");
|
||||
showErrorToast("Không thể gửi tín hiệu SOS");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ export const InfoSection: React.FC<InfoSectionProps> = ({
|
||||
{
|
||||
label: "Thời gian kết thúc",
|
||||
value:
|
||||
fishingLog.end_at !== "0001-01-01T00:00:00Z"
|
||||
fishingLog.end_at.toString() !== "0001-01-01T00:00:00Z"
|
||||
? new Date(fishingLog.end_at).toLocaleString()
|
||||
: "-",
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user