updated email screen to be responsive, fixed banner and fetchUserEmail button

This commit is contained in:
2024-08-10 23:15:52 +08:00
parent b21e270f56
commit 5f974c8d71

View File

@@ -3,6 +3,10 @@ import { View, Text, TouchableOpacity, FlatList, StyleSheet, ActivityIndicator,
import { Ionicons } from '@expo/vector-icons'; import { Ionicons } from '@expo/vector-icons';
import { getEmails, getScannedEmails, getUserInfo } from '../api/qrCodeAPI'; import { getEmails, getScannedEmails, getUserInfo } from '../api/qrCodeAPI';
import { useAuthenticator } from '@aws-amplify/ui-react-native';
import useFetchUserAttributes from '../hooks/useFetchUserAttributes';
import { fetchAuthSession, getCurrentUser, signInWithRedirect } from 'aws-amplify/auth';
const { width: screenWidth, height: screenHeight } = Dimensions.get('window'); const { width: screenWidth, height: screenHeight } = Dimensions.get('window');
@@ -14,6 +18,7 @@ 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 [googleAccessToken, setGoogleAccessToken] = useState<string | null>(null);
useEffect(() => { useEffect(() => {
@@ -24,8 +29,9 @@ const EmailScreen: React.FC = () => {
// Function to fetch user email // Function to fetch user email
const fetchUserEmail = async () => { const fetchUserEmail = async () => {
try { try {
console.log('fetchUserEmail triggered');
const userInfo = await getUserInfo(); const userInfo = await getUserInfo();
setUserEmail(userInfo.email); // Adjust this line based on the actual structure of userInfo 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');
@@ -171,98 +177,89 @@ const styles = StyleSheet.create({
container: { container: {
flex: 1, flex: 1,
backgroundColor: '#f8f0fc', backgroundColor: '#f8f0fc',
padding: 10, paddingHorizontal: screenWidth * 0.025,
paddingTop: 40, // Padding from the top to align content paddingTop: screenHeight * 0.05,
paddingBottom: screenHeight * 0.1, paddingBottom: screenHeight * 0.1,
}, },
headerContainer: { headerContainer: {
flexDirection: 'row', flexDirection: 'row',
alignItems: 'center', alignItems: 'center',
justifyContent: 'space-between', justifyContent: 'space-between',
marginBottom: 10, marginBottom: screenHeight * 0.02,
}, },
emailHeader: { emailHeader: {
fontSize: 18, fontSize: screenWidth * 0.045,
fontWeight: 'bold', fontWeight: 'bold',
color: '#ff69b4', color: '#ff69b4',
}, },
emailListContainer: {
flex: 1,
},
refreshButton: { refreshButton: {
padding: 5, padding: screenWidth * 0.025,
}, },
loadingContainer: { loadingContainer: {
flex: 1, flex: 1,
justifyContent: 'center', justifyContent: 'center',
alignItems: 'center', alignItems: 'center',
}, },
loadingText: {
color: '#ff69b4',
fontSize: screenWidth * 0.04,
},
errorContainer: { errorContainer: {
flex: 1, flex: 1,
justifyContent: 'center', justifyContent: 'center',
alignItems: 'center', alignItems: 'center',
}, },
buttonContainer: { errorText: {
justifyContent: 'center', color: '#ff69b4',
alignItems: 'center', fontSize: screenWidth * 0.04,
marginVertical: 20,
},
button: {
backgroundColor: '#ff69b4',
padding: 10,
borderRadius: 5,
},
buttonText: {
color: '#fff',
fontWeight: 'bold',
}, },
rescanIndicator: { rescanIndicator: {
justifyContent: 'center', justifyContent: 'center',
alignItems: 'center', alignItems: 'center',
marginVertical: 10, marginVertical: screenHeight * 0.015,
}, },
emailListContainer: { rescanText: {
flex: 1,
},
header: {
fontSize: 24,
fontWeight: 'bold',
color: '#ff69b4', color: '#ff69b4',
marginBottom: 10, fontSize: screenWidth * 0.04,
textAlign: 'center',
}, },
messageContainer: { messageContainer: {
backgroundColor: '#fff', backgroundColor: '#fff',
padding: 10, padding: screenWidth * 0.025,
borderRadius: 10, borderRadius: screenWidth * 0.025,
marginBottom: 10, marginBottom: screenHeight * 0.015,
shadowColor: '#000', shadowColor: '#000',
shadowOpacity: 0.1, shadowOpacity: 0.1,
shadowOffset: { width: 0, height: 2 }, shadowOffset: { width: 0, height: screenHeight * 0.002 },
shadowRadius: 5, shadowRadius: screenWidth * 0.025,
elevation: 2, elevation: 2,
}, },
subject: { subject: {
fontSize: 16, fontSize: screenWidth * 0.04,
fontWeight: 'bold', fontWeight: 'bold',
color: '#000', color: '#000',
}, },
date: { date: {
fontSize: 14, fontSize: screenWidth * 0.035,
color: '#555', color: '#555',
}, },
qrCodeContainer: { qrCodeContainer: {
marginBottom: 10, // Add more space between the QR codes marginBottom: screenHeight * 0.015,
}, },
qrCodeLink: { qrCodeLink: {
fontSize: 14, fontSize: screenWidth * 0.035,
color: '#0000ff', color: '#0000ff',
textDecorationLine: 'underline', textDecorationLine: 'underline',
marginVertical: 5, // Add vertical margin for spacing marginVertical: screenHeight * 0.005,
}, },
qrCodeHeader: { qrCodeHeader: {
fontSize: 16, fontSize: screenWidth * 0.04,
fontWeight: 'bold', fontWeight: 'bold',
color: '#ff69b4', color: '#ff69b4',
marginBottom: 5, marginBottom: screenHeight * 0.01,
marginTop: 10, // Add margin at the top for spacing from the previous element marginTop: screenHeight * 0.015,
}, },
banner: { banner: {
position: 'absolute', position: 'absolute',