Added QR Tips and fixed fetchUser Email
This commit is contained in:
@@ -240,4 +240,16 @@ export const deleteEmail = async (messageId: string) => {
|
|||||||
return response;
|
return response;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function to delete all emails
|
// Function to fetch QR code tips
|
||||||
|
export const getQRTips = async () => {
|
||||||
|
try {
|
||||||
|
const response = await apiRequest({
|
||||||
|
method: 'get',
|
||||||
|
url: `${API_BASE_URL}${API_URL_TIPS_GET}`,
|
||||||
|
});
|
||||||
|
return response;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching QR tips:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
BIN
assets/bakcup.png
Normal file
BIN
assets/bakcup.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 57 KiB |
BIN
assets/icon.png
BIN
assets/icon.png
Binary file not shown.
|
Before Width: | Height: | Size: 57 KiB After Width: | Height: | Size: 227 KiB |
18828
package-lock.json
generated
18828
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -25,7 +25,8 @@ const EmailScreen: React.FC = () => {
|
|||||||
|
|
||||||
// Start scanning inbox only once when the component mounts
|
// Start scanning inbox only once when the component mounts
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
startInboxScanning();
|
startInboxScanning();
|
||||||
|
fetchUserEmail();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// Function to fetch user email
|
// Function to fetch user email
|
||||||
|
|||||||
@@ -5,38 +5,63 @@ import { Ionicons } from '@expo/vector-icons';
|
|||||||
import * as ImagePicker from 'expo-image-picker';
|
import * as ImagePicker from 'expo-image-picker';
|
||||||
import RNQRGenerator from 'rn-qr-generator';
|
import RNQRGenerator from 'rn-qr-generator';
|
||||||
import ScannedDataBox from '../components/ScannedDataBox';
|
import ScannedDataBox from '../components/ScannedDataBox';
|
||||||
import { scanQRCode } from '../api/qrCodeAPI';
|
import { scanQRCode, getQRTips } from '../api/qrCodeAPI';
|
||||||
import SettingsScreen from './SettingsScreen';
|
import SettingsScreen from './SettingsScreen';
|
||||||
import NetInfo from '@react-native-community/netinfo';
|
import NetInfo from '@react-native-community/netinfo';
|
||||||
|
|
||||||
const { width: screenWidth, height: screenHeight } = Dimensions.get('window');
|
const { width: screenWidth, height: screenHeight } = Dimensions.get('window');
|
||||||
|
|
||||||
const QRScannerScreen: React.FC = () => {
|
const QRScannerScreen: React.FC = () => {
|
||||||
|
// State management
|
||||||
const [isSettingsModalVisible, setIsSettingsModalVisible] = useState<boolean>(false);
|
const [isSettingsModalVisible, setIsSettingsModalVisible] = useState<boolean>(false);
|
||||||
const [enableTorch, setEnableTorch] = useState<boolean>(false);
|
const [enableTorch, setEnableTorch] = useState<boolean>(false);
|
||||||
const [scanned, setScanned] = useState<boolean>(false);
|
const [scanned, setScanned] = useState<boolean>(false);
|
||||||
const [qrCodeId, setQRCodeId] = useState<string | null>(null); // State for QR code ID
|
const [qrCodeId, setQRCodeId] = useState<string | null>(null);
|
||||||
const [isScannedDataBoxVisible, setIsScannedDataBoxVisible] = useState<boolean>(false); // State for ScannedDataBox visibility
|
const [isScannedDataBoxVisible, setIsScannedDataBoxVisible] = useState<boolean>(false);
|
||||||
const [bannerOpacity] = useState(new Animated.Value(0)); // Initialize bannerOpacity as an Animated.Value
|
const [bannerOpacity] = useState(new Animated.Value(0));
|
||||||
|
const [isConnected, setIsConnected] = useState<boolean>(true);
|
||||||
|
const [qrTip, setQrTip] = useState<string>('Always scan QR codes from trusted sources');
|
||||||
|
|
||||||
|
// Camera permissions and device management
|
||||||
const { hasPermission, requestPermission } = useCameraPermission();
|
const { hasPermission, requestPermission } = useCameraPermission();
|
||||||
const device = useCameraDevice('back');
|
const device = useCameraDevice('back');
|
||||||
const [isConnected, setIsConnected] = useState<boolean>(true); // State for network connection
|
|
||||||
|
|
||||||
|
// Fetch QR Tips and manage polling
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
requestPermission();
|
const fetchTips = async () => {
|
||||||
|
try {
|
||||||
|
const response = await getQRTips();
|
||||||
|
setQrTip(response.tips); // Set the qrTip state to the value of the tips property
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching QR tips:', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
requestPermission(); // Request camera permission on component mount
|
||||||
|
|
||||||
|
// Initial fetch for QR tips
|
||||||
|
fetchTips();
|
||||||
|
|
||||||
|
// Set interval for fetching QR tips every 5 seconds
|
||||||
|
const intervalId = setInterval(fetchTips, 10000);
|
||||||
|
|
||||||
// Subscribe to network state updates
|
// Subscribe to network state updates
|
||||||
const unsubscribe = NetInfo.addEventListener(state => {
|
const unsubscribe = NetInfo.addEventListener(state => {
|
||||||
setIsConnected(state.isConnected);
|
setIsConnected(state.isConnected);
|
||||||
if (!state.isConnected) {
|
if (!state.isConnected) {
|
||||||
showBanner(); // Show the banner when the device is offline
|
showBanner(); // Show banner if the device goes offline
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Unsubscribe when component unmounts
|
// Cleanup on component unmount
|
||||||
return () => unsubscribe();
|
return () => {
|
||||||
|
clearInterval(intervalId); // Clear interval
|
||||||
|
unsubscribe(); // Unsubscribe from network state updates
|
||||||
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// Show an offline banner
|
||||||
const showBanner = () => {
|
const showBanner = () => {
|
||||||
Animated.timing(bannerOpacity, {
|
Animated.timing(bannerOpacity, {
|
||||||
toValue: 1,
|
toValue: 1,
|
||||||
@@ -53,6 +78,7 @@ const QRScannerScreen: React.FC = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Handle payload after scanning QR code
|
||||||
const handlePayload = async (payload: string) => {
|
const handlePayload = async (payload: string) => {
|
||||||
setScanned(true);
|
setScanned(true);
|
||||||
console.info("Decoded QR Code, Payload is: ", payload);
|
console.info("Decoded QR Code, Payload is: ", payload);
|
||||||
@@ -60,44 +86,43 @@ const QRScannerScreen: React.FC = () => {
|
|||||||
try {
|
try {
|
||||||
const response = await scanQRCode(payload);
|
const response = await scanQRCode(payload);
|
||||||
const qrCodeId = response.qrcode.data.id;
|
const qrCodeId = response.qrcode.data.id;
|
||||||
// Store the QR code ID for later use
|
setQRCodeId(qrCodeId); // Store QR code ID
|
||||||
setQRCodeId(qrCodeId);
|
setIsScannedDataBoxVisible(true); // Show the ScannedDataBox pop-up
|
||||||
setIsScannedDataBoxVisible(true); // Show ScannedDataBox pop-up
|
|
||||||
console.log("QR code scanned successfully, ID:", qrCodeId);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error scanning QR code:", error);
|
console.error("Error scanning QR code:", error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Use the camera to scan QR codes
|
||||||
const codeScanner = useCodeScanner({
|
const codeScanner = useCodeScanner({
|
||||||
codeTypes: ['qr'], // Only scan QR codes
|
codeTypes: ['qr'], // Only scan QR codes
|
||||||
onCodeScanned: (codes) => {
|
onCodeScanned: (codes) => {
|
||||||
if (!scanned && codes[0]?.value) {
|
if (!scanned && codes[0]?.value) {
|
||||||
handlePayload(codes[0].value); // Extract and handle the value only if it exists
|
handlePayload(codes[0].value); // Handle the QR code value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Read QR code from an image
|
||||||
const readQRFromImage = async () => {
|
const readQRFromImage = async () => {
|
||||||
console.log("Reading QR code from image");
|
console.log("Reading QR code from image");
|
||||||
|
|
||||||
const result = await ImagePicker.launchImageLibraryAsync({
|
const result = await ImagePicker.launchImageLibraryAsync({
|
||||||
mediaTypes: ImagePicker.MediaTypeOptions.Images,
|
mediaTypes: ImagePicker.MediaTypeOptions.Images,
|
||||||
allowsEditing: false, // Don't ask user to crop images
|
allowsEditing: false,
|
||||||
quality: 1,
|
quality: 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (result && result.assets && result.assets.length > 0 && result.assets[0].uri) { // Ensure the uri is not empty
|
if (result && result.assets && result.assets.length > 0 && result.assets[0].uri) {
|
||||||
try {
|
try {
|
||||||
const detectionResult = await RNQRGenerator.detect({
|
const detectionResult = await RNQRGenerator.detect({
|
||||||
uri: result.assets[0].uri, // Local path of the image
|
uri: result.assets[0].uri,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { values } = detectionResult;
|
const { values } = detectionResult;
|
||||||
|
|
||||||
if (values.length > 0) {
|
if (values.length > 0) {
|
||||||
handlePayload(values[0]); // Use the first detected QR code value
|
handlePayload(values[0]); // Handle the first detected QR code value
|
||||||
console.log('QR code data from image:', values[0]);
|
|
||||||
} else {
|
} else {
|
||||||
console.log("No QR code found in the selected image");
|
console.log("No QR code found in the selected image");
|
||||||
}
|
}
|
||||||
@@ -107,10 +132,12 @@ const QRScannerScreen: React.FC = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Check for camera permissions
|
||||||
if (!hasPermission) {
|
if (!hasPermission) {
|
||||||
return <Text>Requesting camera permission...</Text>;
|
return <Text>Requesting camera permission...</Text>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wait for the device to be ready
|
||||||
if (!device) {
|
if (!device) {
|
||||||
return <Text>Loading camera...</Text>;
|
return <Text>Loading camera...</Text>;
|
||||||
}
|
}
|
||||||
@@ -156,6 +183,14 @@ const QRScannerScreen: React.FC = () => {
|
|||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
|
{/* QR Code Tips Below Camera Container */}
|
||||||
|
<View style={styles.tipsContainer}>
|
||||||
|
<View style={styles.iconTextRow}>
|
||||||
|
<Ionicons name="bulb" size={24} color="red" />
|
||||||
|
<Text style={styles.tipsText}>{qrTip}</Text>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
|
||||||
{/* Scanned Data Box as a pop-up */}
|
{/* Scanned Data Box as a pop-up */}
|
||||||
{isScannedDataBoxVisible && (
|
{isScannedDataBoxVisible && (
|
||||||
<View style={styles.scannedDataBoxPopup}>
|
<View style={styles.scannedDataBoxPopup}>
|
||||||
@@ -195,6 +230,7 @@ const QRScannerScreen: React.FC = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Stylesheet
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
container: {
|
container: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
@@ -232,18 +268,6 @@ const styles = StyleSheet.create({
|
|||||||
top: screenHeight * 0.05,
|
top: screenHeight * 0.05,
|
||||||
right: 20,
|
right: 20,
|
||||||
},
|
},
|
||||||
splashContainer: {
|
|
||||||
flex: 1,
|
|
||||||
justifyContent: 'center',
|
|
||||||
alignItems: 'center',
|
|
||||||
backgroundColor: '#f8f0fc',
|
|
||||||
height: '100%',
|
|
||||||
width: '100%',
|
|
||||||
},
|
|
||||||
camera: {
|
|
||||||
width: '100%',
|
|
||||||
height: '100%',
|
|
||||||
},
|
|
||||||
flashButton: {
|
flashButton: {
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
bottom: screenHeight * 0.025,
|
bottom: screenHeight * 0.025,
|
||||||
@@ -268,7 +292,7 @@ const styles = StyleSheet.create({
|
|||||||
},
|
},
|
||||||
scannedDataBoxPopup: {
|
scannedDataBoxPopup: {
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
top: '20%',
|
top: '20%',
|
||||||
left: '5%',
|
left: '5%',
|
||||||
right: '5%',
|
right: '5%',
|
||||||
zIndex: 2,
|
zIndex: 2,
|
||||||
@@ -278,7 +302,7 @@ const styles = StyleSheet.create({
|
|||||||
elevation: 5,
|
elevation: 5,
|
||||||
},
|
},
|
||||||
settingsModal: {
|
settingsModal: {
|
||||||
backgroundColor: 'rgba(0, 0, 0, 0.5)', // Semi-transparent background
|
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
||||||
},
|
},
|
||||||
settingsModalContainer: {
|
settingsModalContainer: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
@@ -306,23 +330,42 @@ const styles = StyleSheet.create({
|
|||||||
},
|
},
|
||||||
banner: {
|
banner: {
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
top: screenHeight * 0.4, // Adjusts the banner to appear in the middle of the screen
|
top: screenHeight * 0.4,
|
||||||
left: screenWidth * 0.1, // Adjust these values to center the banner as needed
|
left: screenWidth * 0.1,
|
||||||
right: screenWidth * 0.1,
|
right: screenWidth * 0.1,
|
||||||
backgroundColor: '#ff69b4',
|
backgroundColor: '#ff69b4',
|
||||||
paddingVertical: screenHeight * 0.02, // Adjust the height of the banner
|
paddingVertical: screenHeight * 0.02,
|
||||||
paddingHorizontal: screenWidth * 0.05,
|
paddingHorizontal: screenWidth * 0.05,
|
||||||
borderRadius: screenWidth * 0.05,
|
borderRadius: screenWidth * 0.05,
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
zIndex: 10, // Ensure it appears above other elements
|
zIndex: 10,
|
||||||
},
|
},
|
||||||
bannerText: {
|
bannerText: {
|
||||||
color: '#fff',
|
color: '#fff',
|
||||||
fontWeight: 'bold',
|
fontWeight: 'bold',
|
||||||
textAlign: 'center',
|
textAlign: 'center',
|
||||||
fontSize: screenWidth * 0.04,
|
fontSize: screenWidth * 0.04,
|
||||||
}
|
},
|
||||||
|
tipsContainer: {
|
||||||
|
backgroundColor: '#fff', // Make sure the container background matches the white box
|
||||||
|
padding: 10,
|
||||||
|
borderRadius: 10,
|
||||||
|
alignItems: 'center',
|
||||||
|
marginTop: 10, // Space from the camera container
|
||||||
|
},
|
||||||
|
iconTextRow: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center', // This will align the icon and text vertically
|
||||||
|
},
|
||||||
|
tipsText: {
|
||||||
|
color: '#f41c87', // Adjusted color to match the pink theme
|
||||||
|
fontSize: 16,
|
||||||
|
textAlign: 'center',
|
||||||
|
marginLeft: 5, // Add some spacing between the icon and the text
|
||||||
|
paddingHorizontal: 10, // Add horizontal padding to ensure text isn't too close to the edges
|
||||||
|
},
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default QRScannerScreen;
|
export default QRScannerScreen;
|
||||||
|
|||||||
Reference in New Issue
Block a user