Updated EmailScreen to pass QR-ID to ScannedDataBox

This commit is contained in:
2024-08-12 20:44:10 +08:00
parent 9b81225fb1
commit 5f20256c6e
21 changed files with 18818 additions and 36 deletions

View File

@@ -1,4 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.safeqr.safeqr">
<uses-permission android:name="android.permission.CAMERA"/> <uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
@@ -14,9 +14,11 @@
</intent> </intent>
</queries> </queries>
<application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:allowBackup="true" android:theme="@style/AppTheme"> <application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:allowBackup="true" android:theme="@style/AppTheme">
<meta-data android:name="expo.modules.updates.ENABLED" android:value="false"/> <meta-data android:name="expo.modules.updates.ENABLED" android:value="true"/>
<meta-data android:name="expo.modules.updates.EXPO_SDK_VERSION" android:value="51.0.0"/>
<meta-data android:name="expo.modules.updates.EXPO_UPDATES_CHECK_ON_LAUNCH" android:value="ALWAYS"/> <meta-data android:name="expo.modules.updates.EXPO_UPDATES_CHECK_ON_LAUNCH" android:value="ALWAYS"/>
<meta-data android:name="expo.modules.updates.EXPO_UPDATES_LAUNCH_WAIT_MS" android:value="0"/> <meta-data android:name="expo.modules.updates.EXPO_UPDATES_LAUNCH_WAIT_MS" android:value="0"/>
<meta-data android:name="expo.modules.updates.EXPO_UPDATE_URL" android:value="https://exp.host/@piggyinu/safeqr"/>
<activity android:name=".MainActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:theme="@style/Theme.App.SplashScreen" android:exported="true" android:screenOrientation="portrait"> <activity android:name=".MainActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:theme="@style/Theme.App.SplashScreen" android:exported="true" android:screenOrientation="portrait">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN"/>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 61 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 61 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 120 KiB

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 120 KiB

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 189 KiB

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 189 KiB

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

View File

@@ -5,6 +5,7 @@
<item name="android:editTextBackground">@drawable/rn_edit_text_material</item> <item name="android:editTextBackground">@drawable/rn_edit_text_material</item>
<item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimary">@color/colorPrimary</item>
<item name="android:statusBarColor">#ffffff</item> <item name="android:statusBarColor">#ffffff</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
</style> </style>
<style name="ResetEditText" parent="@android:style/Widget.EditText"> <style name="ResetEditText" parent="@android:style/Widget.EditText">
<item name="android:padding">0dp</item> <item name="android:padding">0dp</item>

View File

@@ -58,4 +58,5 @@ EX_DEV_CLIENT_NETWORK_INSPECTOR=true
# Use legacy packaging to compress native libraries in the resulting APK. # Use legacy packaging to compress native libraries in the resulting APK.
expo.useLegacyPackaging=false expo.useLegacyPackaging=false
expo.jsEngine=jsc
VisionCamera_enableCodeScanner=true VisionCamera_enableCodeScanner=true

View File

@@ -332,9 +332,12 @@ const { text: encryptionText, icon: encryptionIcon } = getEncryptionStatus(encry
{type === 'TEL' && ( {type === 'PHONE' && (
<TouchableOpacity style={styles.iconButton} onPress={() => Linking.openURL(contents)}> <TouchableOpacity style={styles.iconButton} onPress={() => Linking.openURL(contents)}>
<View style={styles.dividerHorizontal} />
<Ionicons name="call-outline" size={screenWidth * 0.045} color="#2196F3" /> <Ionicons name="call-outline" size={screenWidth * 0.045} color="#2196F3" />
{/* Divider */}
<Text style={styles.iconText}>Call Number</Text> <Text style={styles.iconText}>Call Number</Text>
</TouchableOpacity> </TouchableOpacity>
)} )}
@@ -347,14 +350,20 @@ const { text: encryptionText, icon: encryptionIcon } = getEncryptionStatus(encry
Linking.openURL(smsUrl).catch(err => console.error('Error sending SMS:', err)); Linking.openURL(smsUrl).catch(err => console.error('Error sending SMS:', err));
}} }}
> >
{/* Divider */}
<View style={styles.dividerHorizontal} />
<Ionicons name="chatbubble-outline" size={screenWidth * 0.045} color="#2196F3" /> <Ionicons name="chatbubble-outline" size={screenWidth * 0.045} color="#2196F3" />
<Text style={styles.iconText}>Send SMS</Text> <Text style={styles.iconText}>Send SMS</Text>
</TouchableOpacity> </TouchableOpacity>
)} )}
{type === 'EMAIL' && ( {type === 'EMAIL' && (
<TouchableOpacity style={styles.iconButton} onPress={() => Linking.openURL(contents)}> <TouchableOpacity style={styles.iconButton} onPress={() => Linking.openURL(contents)}>
{/* Divider */}
<View style={styles.dividerHorizontal} />
<Ionicons name="mail-outline" size={screenWidth * 0.045} color="#2196F3" /> <Ionicons name="mail-outline" size={screenWidth * 0.045} color="#2196F3" />
<Text style={styles.iconText}>Send Email</Text> <Text style={styles.iconText}>Send Email</Text>
</TouchableOpacity> </TouchableOpacity>
)} )}

18739
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,10 +1,11 @@
import React, { useState, useEffect, useCallback } from 'react'; import React, { useState, useEffect, useCallback } from 'react';
import { View, Text, TouchableOpacity, FlatList, StyleSheet, ActivityIndicator, Alert, Animated, Dimensions } from 'react-native'; import { View, Text, TouchableOpacity, FlatList, StyleSheet, ActivityIndicator, Alert, Animated, Dimensions, Modal } from 'react-native';
import { Ionicons } from '@expo/vector-icons'; import { Ionicons } from '@expo/vector-icons';
import { useFocusEffect } from '@react-navigation/native'; import { useFocusEffect } from '@react-navigation/native';
import { getEmails, getScannedEmails, getUserInfo } from '../api/qrCodeAPI'; import { getEmails, getScannedEmails, getUserInfo } from '../api/qrCodeAPI';
import { fetchAuthSession } from 'aws-amplify/auth'; import { fetchAuthSession } from 'aws-amplify/auth';
import { Buffer } from 'buffer'; import { Buffer } from 'buffer';
import ScannedDataBox from '../components/ScannedDataBox';
const { width: screenWidth, height: screenHeight } = Dimensions.get('window'); const { width: screenWidth, height: screenHeight } = Dimensions.get('window');
@@ -16,7 +17,9 @@ const EmailScreen: React.FC = () => {
const [error, setError] = useState(null); const [error, setError] = useState(null);
const [userEmail, setUserEmail] = useState(''); const [userEmail, setUserEmail] = useState('');
const [bannerOpacity] = useState(new Animated.Value(0)); const [bannerOpacity] = useState(new Animated.Value(0));
const [isModalVisible, setIsModalVisible] = useState(false);
const [selectedQrCodeId, setSelectedQrCodeId] = useState(null);
useEffect(() => { useEffect(() => {
fetchUserEmail(); fetchUserEmail();
}, []); }, []);
@@ -26,7 +29,7 @@ const EmailScreen: React.FC = () => {
try { try {
console.log('fetchUserEmail triggered'); console.log('fetchUserEmail triggered');
const userInfo = await getUserInfo(); const userInfo = await getUserInfo();
setUserEmail(userInfo.email); setUserEmail(userInfo.email);
} catch (error) { } catch (error) {
console.error('Error fetching user email:', error); console.error('Error fetching user email:', error);
setUserEmail('Error fetching email'); setUserEmail('Error fetching email');
@@ -42,15 +45,15 @@ const EmailScreen: React.FC = () => {
// Fetch the current authentication session // Fetch the current authentication session
const { tokens } = await fetchAuthSession(); const { tokens } = await fetchAuthSession();
const idToken = tokens.idToken.toString(); const idToken = tokens.idToken.toString();
const parts = idToken.split('.'); const parts = idToken.split('.');
const payload = parts[1]; const payload = parts[1];
const decodedPayload = Buffer.from(payload, 'base64').toString('utf8'); const decodedPayload = Buffer.from(payload, 'base64').toString('utf8');
const parsedPayload = JSON.parse(decodedPayload); const parsedPayload = JSON.parse(decodedPayload);
const googleAccessToken = parsedPayload["custom:access_token"]; const googleAccessToken = parsedPayload["custom:access_token"];
const googleRefreshToken = parsedPayload["custom:refresh_token"]; const googleRefreshToken = parsedPayload["custom:refresh_token"];
if (googleAccessToken && googleRefreshToken) { if (googleAccessToken && googleRefreshToken) {
// Use the fetched tokens to initiate email fetching // Use the fetched tokens to initiate email fetching
await getEmails(googleAccessToken, googleRefreshToken); await getEmails(googleAccessToken, googleRefreshToken);
@@ -128,6 +131,12 @@ const EmailScreen: React.FC = () => {
}, [startPollingForScannedEmails]) }, [startPollingForScannedEmails])
); );
const handleUrlClick = (id) => {
console.log('handleURLClik ID :',)
setSelectedQrCodeId(id);
setIsModalVisible(true);
};
return ( return (
<View style={styles.container}> <View style={styles.container}>
{loading && ( {loading && (
@@ -163,45 +172,48 @@ const EmailScreen: React.FC = () => {
<Text style={styles.date}>{item.date}</Text> <Text style={styles.date}>{item.date}</Text>
{selectedMessage === item && ( {selectedMessage === item && (
<View style={styles.emailListContainer}> <View style={styles.emailListContainer}>
{item.qrCodeByContentId && ( <Text style={styles.qrCodeHeader}>Decoded QR Codes:</Text>
<View> {item.decodedContentsDetails?.map((details, index) => (
<Text style={styles.qrCodeHeader}>QR Codes by Content ID:</Text> <View key={index} style={styles.qrCodeContainer}>
{item.qrCodeByContentId.map((qrCode, index) => ( <TouchableOpacity onPress={() => handleUrlClick(details.data.id)}>
<View key={index} style={styles.qrCodeContainer}> <Text style={styles.qrCodeLink}>{details.data.contents}</Text>
{qrCode.decodedContent.map((url, i) => ( </TouchableOpacity>
<TouchableOpacity key={i} onPress={() => Alert.alert("Testing")}>
<Text style={styles.qrCodeLink}>{url}</Text>
</TouchableOpacity>
))}
</View>
))}
</View> </View>
)} ))}
{item.qrCodeByURL && (
<View>
<Text style={styles.qrCodeHeader}>Decoded QR Codes:</Text>
{item.qrCodeByURL.map((qrCode, index) => (
<View key={index} style={styles.qrCodeContainer}>
{qrCode.decodedContent.map((url, i) => (
<TouchableOpacity key={i} onPress={() => Alert.alert("Testing")}>
<Text style={styles.qrCodeLink}>{url}</Text>
</TouchableOpacity>
))}
</View>
))}
</View>
)}
</View> </View>
)} )}
</TouchableOpacity> </TouchableOpacity>
)} )}
/> />
</> </>
)} )}
<Animated.View style={[styles.banner, { opacity: bannerOpacity }]}> <Animated.View style={[styles.banner, { opacity: bannerOpacity }]}>
<Text style={styles.bannerText}>Scanning emails in the background. This may take a while...</Text> <Text style={styles.bannerText}>Scanning emails in the background. This may take a while...</Text>
</Animated.View> </Animated.View>
{/* Modal for ScannedDataBox */}
<Modal
visible={isModalVisible}
transparent={true}
animationType="slide"
onRequestClose={() => setIsModalVisible(false)}
>
{/* The greyspace outside , made clickable to close the modl */}
<TouchableOpacity
style={styles.modalContainer}
activeOpacity={1}
onPressOut={() => setIsModalVisible(false)}
>
{/* Ensure ScannedDataBox does not render another modal */}
<ScannedDataBox qrCodeId={selectedQrCodeId} clearScanData={() => setIsModalVisible(false)} />
</TouchableOpacity>
</Modal>
</View> </View>
); );
}; };
@@ -312,6 +324,24 @@ const styles = StyleSheet.create({
textAlign: 'center', textAlign: 'center',
fontSize: screenWidth * 0.04, fontSize: screenWidth * 0.04,
}, },
modalContainer: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'rgba(0, 0, 0, 0.5)', // dark overlay
},
innerModalContainer: {
backgroundColor: '#ffe6f0', // pink box color
padding: screenWidth * 0.05,
borderRadius: screenWidth * 0.03,
alignItems: 'center',
},
modalCloseButton: {
position: 'absolute',
top: screenWidth * 0.02,
right: screenWidth * 0.02,
zIndex: 1, // Ensure it is above other content
}
}); });
export default EmailScreen; export default EmailScreen;