From 7cb5cbbe34b5a7b5f8b7df3e79facd8074f9cd3b Mon Sep 17 00:00:00 2001 From: Isky Date: Tue, 6 Aug 2024 11:38:40 +0800 Subject: [PATCH] updated UI for relative screensize. Handle long payload by truncating the displayes content --- components/ScannedDataBox.tsx | 276 ++++++++++++++++++++-------------- screens/EmailScreen.tsx | 6 +- 2 files changed, 164 insertions(+), 118 deletions(-) diff --git a/components/ScannedDataBox.tsx b/components/ScannedDataBox.tsx index 2cd7c71..f4efce8 100644 --- a/components/ScannedDataBox.tsx +++ b/components/ScannedDataBox.tsx @@ -1,11 +1,12 @@ import React, { useEffect, useState } from 'react'; -import { View, Text, StyleSheet, Image, TouchableOpacity, Modal, ActivityIndicator, Alert } from 'react-native'; +import { View, Text, StyleSheet, Image, TouchableOpacity, Modal, ActivityIndicator, ScrollView, Dimensions } from 'react-native'; import QRCode from 'react-native-qrcode-svg'; -import { Ionicons, MaterialCommunityIcons, SimpleLineIcons } from '@expo/vector-icons'; // Import icons +import { Ionicons, MaterialCommunityIcons, SimpleLineIcons } from '@expo/vector-icons'; import { getQRCodeDetails } from '../api/qrCodeAPI'; -import SecureWebView from '../components/SecureWebView'; // Import the SecureWebView component +import SecureWebView from '../components/SecureWebView'; + +const { width: screenWidth, height: screenHeight } = Dimensions.get('window'); -// Define Props for ScannedDataBox component interface ScannedDataBoxProps { qrCodeId: string; clearScanData: () => void; @@ -14,6 +15,7 @@ interface ScannedDataBoxProps { const ScannedDataBox: React.FC = ({ qrCodeId, clearScanData }) => { const [isModalVisible, setIsModalVisible] = useState(false); const [isRedirectModalVisible, setIsRedirectModalVisible] = useState(false); + const [isContentModalVisible, setIsContentModalVisible] = useState(false); const [qrDetails, setQrDetails] = useState(null); const [isWebViewVisible, setIsWebViewVisible] = useState(false); const [webViewUrl, setWebViewUrl] = useState(''); @@ -42,7 +44,6 @@ const ScannedDataBox: React.FC = ({ qrCodeId, clearScanData ); } - // Handle cases where data might be undefined const data = qrDetails.data || {}; const details = qrDetails.details || {}; const type = data.info?.type || 'Undefined'; @@ -52,7 +53,6 @@ const ScannedDataBox: React.FC = ({ qrCodeId, clearScanData const securityHeaders = details.hstsHeader || ['No Headers']; const redirectChain = details.redirectChain || ['No Redirects']; - // Determine the result text based on scan result const getResultText = () => { if (!secureConnection || redirects > 0) { return 'DANGEROUS'; @@ -63,7 +63,6 @@ const ScannedDataBox: React.FC = ({ qrCodeId, clearScanData } }; - // Determine the result color based on result text const getResultColor = () => { const result = getResultText(); if (result === 'DANGEROUS') { @@ -77,97 +76,102 @@ const ScannedDataBox: React.FC = ({ qrCodeId, clearScanData } }; - // Determine the appropriate icon for redirects const getRedirectIcon = () => { if (redirects === 0) { - return ; + return ; } else if (redirects <= 2) { - return ; + return ; } else { - return ; + return ; } }; - // Open the WebView for the URL const openWebView = (url: string) => { setWebViewUrl(url); setIsWebViewVisible(true); }; + const truncateContent = (content: string, length: number) => { + if (content.length > length) { + return `${content.substring(0, length)}...`; + } + return content; + }; + return ( - {/* Close button */} - + - {/* Display scanned data */} - + - {contents} - - - {data.createdAt ? new Date(data.createdAt).toLocaleString() : 'Invalid Date'} - - - - Result: {getResultText()} + setIsContentModalVisible(true)}> + {truncateContent(contents, 30)} {/* Truncated content further */} - - {/* Display data type */} - - Type: {type} - - {'\n'} + + + + + + + {data.createdAt ? new Date(data.createdAt).toLocaleString() : 'Invalid Date'} + Description: {type} + {'\n'} + + + + + + Result: {getResultText()} + - {/* Display scan checks */} {type === 'URL' && ( <> {secureConnection ? ( <> - - Secure Connection + + Secure Connection ) : ( <> - - Not Secure + + Not Secure )} setIsRedirectModalVisible(true)}> {getRedirectIcon()} Redirects - + )} {type === 'SMS' && ( <> - Recipient Phone Number: {details.phone || 'Undefined'} - Message Content: {details.message || 'Undefined'} + Recipient Phone Number: {details.phone || 'Undefined'} + Message Content: {details.message || 'Undefined'} )} {type === 'TEXT' && ( - <> - Content: {contents} - + setIsContentModalVisible(true)}> + + Content: {truncateContent(contents, 30)} {/* Truncated content further */} + + )} - - setIsModalVisible(true)}> - + Security Headers - + - {/* Modal for security headers */} = ({ qrCodeId, clearScanData - {/* Modal for redirects */} = ({ qrCodeId, clearScanData - {/* Action buttons */} - + setIsContentModalVisible(false)} + > + + + Full Content + + {contents} + + setIsContentModalVisible(false)}> + Close + + + + + + {type === 'URL' && ( openWebView(contents)}> - + Open )} - {/* SecureWebView Modal */} { try { // Call to start email fetching process const response = await getEmails( - 'Access Token here', - 'Refresh Token here' + 'ya29.a0AcM612zTwLojArYvmKxAKiUKL1eBIs04ZBN2dp53BShPcPAhZigjmivq-mQmT6BgF5G1ernMKb2LCHmRgX3vlSaBj2hD8JDi7kvpexduM-_x8aG7QorKfyB2z6yJzFrwVes2Y9tHhb9vWUAqbPdiL4wqNqeE5HxZNhoaCgYKAS0SARISFQHGX2MikJkWByj0FaiKBj3jU7svGg0170', + '1//0g-hOrh4_72p3CgYIARAAGBASNwF-L9IrYVyuPL7WPbsm_ePtzFugduBLmdSr3UpQx7GMSt17KcS2Y_Z3v4N5wZiWua88RFjJ3Zk' ); setRescanLoading(false); } catch (error) { @@ -103,7 +103,7 @@ const EmailScreen: React.FC = () => { )} {item.qrCodeByURL && ( - QR Codes by URL: + Decoded QR Codes: {item.qrCodeByURL.map((qrCode, index) => ( {qrCode.decodedContent.map((url, i) => (