diff --git a/screens/EmailScreen.tsx b/screens/EmailScreen.tsx index 9345307..b0dec22 100644 --- a/screens/EmailScreen.tsx +++ b/screens/EmailScreen.tsx @@ -1,6 +1,7 @@ import React, { useState, useEffect } from 'react'; -import { View, Text, TouchableOpacity, FlatList, StyleSheet, ActivityIndicator, Alert } from 'react-native'; -import { getEmails, getScannedEmails } from '../api/qrCodeAPI'; +import { View, Text, TouchableOpacity, FlatList, StyleSheet, ActivityIndicator, Alert, Animated } from 'react-native'; +import { Ionicons } from '@expo/vector-icons'; +import { getEmails, getScannedEmails, getUserInfo } from '../api/qrCodeAPI'; const EmailScreen: React.FC = () => { const [selectedMessage, setSelectedMessage] = useState(null); @@ -8,14 +9,29 @@ const EmailScreen: React.FC = () => { const [loading, setLoading] = useState(true); const [rescanLoading, setRescanLoading] = useState(false); const [error, setError] = useState(null); - + const [userEmail, setUserEmail] = useState(''); + const [bannerOpacity] = useState(new Animated.Value(0)); + useEffect(() => { startPollingForScannedEmails(); + fetchUserEmail(); }, []); + // Function to fetch user email + const fetchUserEmail = async () => { + try { + const userInfo = await getUserInfo(); + setUserEmail(userInfo.email); // Adjust this line based on the actual structure of userInfo + } catch (error) { + console.error('Error fetching user email:', error); + setUserEmail('Error fetching email'); + } + }; + // Function to initiate the email fetching process const initiateEmailFetch = async () => { setRescanLoading(true); + showBanner(); try { // Call to start email fetching process const response = await getEmails( @@ -30,6 +46,23 @@ const EmailScreen: React.FC = () => { } }; + // Function to show the banner + const showBanner = () => { + Animated.timing(bannerOpacity, { + toValue: 1, + duration: 500, + useNativeDriver: true, + }).start(() => { + setTimeout(() => { + Animated.timing(bannerOpacity, { + toValue: 0, + duration: 500, + useNativeDriver: true, + }).start(); + }, 3000); + }); + }; + // Function to poll for scanned emails const startPollingForScannedEmails = () => { const pollingInterval = setInterval(async () => { @@ -68,9 +101,10 @@ const EmailScreen: React.FC = () => { )} {emailData && ( <> - - - Rescan Inbox + + Email: {userEmail} + + {rescanLoading && ( @@ -122,12 +156,34 @@ const EmailScreen: React.FC = () => { /> )} + + Scanning emails in the background. This may take a while... + ); }; const styles = StyleSheet.create({ - // ... (rest of your styles) + container: { + flex: 1, + backgroundColor: '#f8f0fc', + padding: 10, + paddingTop: 40, // Padding from the top to align content + }, + headerContainer: { + flexDirection: 'row', + alignItems: 'center', + justifyContent: 'space-between', + marginBottom: 10, + }, + emailHeader: { + fontSize: 18, + fontWeight: 'bold', + color: '#ff69b4', + }, + refreshButton: { + padding: 5, + }, loadingContainer: { flex: 1, justifyContent: 'center', @@ -138,11 +194,6 @@ const styles = StyleSheet.create({ justifyContent: 'center', alignItems: 'center', }, - container: { - flex: 1, - backgroundColor: '#f8f0fc', - padding: 10, - }, buttonContainer: { justifyContent: 'center', alignItems: 'center', @@ -207,7 +258,21 @@ const styles = StyleSheet.create({ color: '#ff69b4', marginBottom: 5, marginTop: 10, // Add margin at the top for spacing from the previous element - } + }, + banner: { + position: 'absolute', + top: 0, + left: 0, + right: 0, + backgroundColor: '#ff69b4', + padding: 10, + alignItems: 'center', + justifyContent: 'center', + }, + bannerText: { + color: '#fff', + fontWeight: 'bold', + }, }); export default EmailScreen; diff --git a/screens/HistoryScreen.tsx b/screens/HistoryScreen.tsx index abce2da..0af4e70 100644 --- a/screens/HistoryScreen.tsx +++ b/screens/HistoryScreen.tsx @@ -1,15 +1,16 @@ import React, { useCallback, useState, useEffect } from 'react'; -import { View, Text, StyleSheet, FlatList, TouchableOpacity, Image, Modal, ActivityIndicator } from 'react-native'; +import { View, Text, StyleSheet, FlatList, TouchableOpacity, Image, Modal, ActivityIndicator, Dimensions } from 'react-native'; import { useDispatch, useSelector } from 'react-redux'; import ScannedDataBox from '../components/ScannedDataBox'; import { Ionicons } from '@expo/vector-icons'; import { RootState, AppDispatch } from '../store'; import { QRCodeType } from '../types'; import { toggleBookmark, deleteQRCode, setScannedHistories } from '../reducers/qrCodesReducer'; - import useFetchUserAttributes from '../hooks/useFetchUserAttributes'; import { getScannedHistories } from '../api/qrCodeAPI'; +const { width: screenWidth, height: screenHeight } = Dimensions.get('window'); + const HistoryScreen: React.FC = () => { const dispatch = useDispatch(); const histories = useSelector((state: RootState) => state.qrCodes.histories); @@ -19,10 +20,8 @@ const HistoryScreen: React.FC = () => { const [isModalVisible, setIsModalVisible] = useState(false); const [historiesLoading, setHistoriesLoading] = useState(false); const [historiesError, setHistoriesError] = useState(null); - const [selectedQrCodeId, setSelectedQrCodeId] = useState(null); - const fetchHistories = useCallback(async () => { if (!userAttributes?.sub) return; @@ -50,7 +49,6 @@ const HistoryScreen: React.FC = () => { } }, [dispatch, userAttributes]); - const filteredQrCodes = showBookmarks ? histories.filter(qr => qr.bookmarked) : histories; const handleItemPress = (item: QRCodeType) => { @@ -60,12 +58,9 @@ const HistoryScreen: React.FC = () => { const clearSelectedData = () => { setSelectedQrCodeId(null); }; - - return ( - {/* Header for toggling between History and Bookmarks */} { setShowBookmarks(false); clearSelectedData(); }}> History @@ -74,25 +69,21 @@ const HistoryScreen: React.FC = () => { Bookmarks - - {/* Loading Indicator */} + {historiesLoading && } - {/* Display message when there are no histories or bookmarks */} {!historiesLoading && filteredQrCodes.length === 0 && ( {showBookmarks ? 'No bookmarks available' : 'No history available'} )} - {/* Display scanned data details */} {selectedQrCodeId && ( - - - -)} + + + + )} - {/* List of QR codes */} ( @@ -110,13 +101,13 @@ const HistoryScreen: React.FC = () => { dispatch(toggleBookmark({ userId: userAttributes.sub, qrCode: item}))}> - + { setQrCodeToDelete(item.data.id); setIsModalVisible(true); }}> - + @@ -125,7 +116,6 @@ const HistoryScreen: React.FC = () => { contentContainerStyle={styles.flatListContent} /> - {/* Modal for delete confirmation */}