Updated SettingScreen

Adjusted QRScannerscreen when calling settingscreen
This commit is contained in:
2024-08-14 17:13:03 +08:00
parent 170997097f
commit 549dc1efde
2 changed files with 132 additions and 41 deletions

View File

@@ -158,7 +158,7 @@ const QRScannerScreen: React.FC = () => {
<Camera <Camera
style={StyleSheet.absoluteFill} style={StyleSheet.absoluteFill}
device={device} device={device}
isActive={true} isActive={!isSettingsModalVisible} // Disable the camera when settings modal is open
torch={enableTorch ? 'on' : 'off'} torch={enableTorch ? 'on' : 'off'}
codeScanner={codeScanner} codeScanner={codeScanner}
/> />
@@ -252,17 +252,22 @@ const styles = StyleSheet.create({
}, },
welcomeText: { welcomeText: {
textAlign: 'center', textAlign: 'center',
fontSize: 20, fontSize: 15,
marginVertical: 10, marginVertical: 10,
color: 'black', color: 'black',
}, },
cameraContainer: { cameraContainer: {
height: '50%', width: '100%', // Adjust the width as needed
height: '45%', // Adjust the height as needed
alignItems: 'center', alignItems: 'center',
justifyContent: 'center', justifyContent: 'center',
borderRadius: 10, borderRadius: 10,
overflow: 'hidden', overflow: 'hidden',
alignSelf: 'center', // Center the container horizontally
marginTop: '10%', // Adjust the top margin to position it vertically in the middle
}, },
settingsButton: { settingsButton: {
position: 'absolute', position: 'absolute',
top: screenHeight * 0.05, top: screenHeight * 0.05,
@@ -307,15 +312,15 @@ const styles = StyleSheet.create({
settingsModalContainer: { settingsModalContainer: {
flex: 1, flex: 1,
justifyContent: 'center', justifyContent: 'center',
backgroundColor: 'rgba(0, 0, 0, 0.5)', backgroundColor: '#f8f0fc', // Full pink background to match the app's theme
}, },
settingsModalContent: { settingsModalContent: {
width: '100%', flex: 1,
height: '80%', backgroundColor: '#f8f0fc', // Full pink background for the content as well
backgroundColor: 'white',
padding: screenWidth * 0.05, padding: screenWidth * 0.05,
borderTopLeftRadius: screenWidth * 0.025, borderTopLeftRadius: 0, // Remove border radius to avoid white edges
borderTopRightRadius: screenWidth * 0.025, borderTopRightRadius: 0, // Remove border radius to avoid white edges
alignItems: 'center', alignItems: 'center',
}, },
closeButton: { closeButton: {

View File

@@ -2,9 +2,10 @@ import React, { useEffect, useState } from 'react';
import { View, Text, StyleSheet, TouchableOpacity, Linking, Alert, Button } from 'react-native'; import { View, Text, StyleSheet, TouchableOpacity, Linking, Alert, Button } from 'react-native';
import { useAuthenticator } from '@aws-amplify/ui-react-native'; import { useAuthenticator } from '@aws-amplify/ui-react-native';
import useFetchUserAttributes from '../hooks/useFetchUserAttributes'; import useFetchUserAttributes from '../hooks/useFetchUserAttributes';
import { fetchAuthSession, getCurrentUser, signInWithRedirect } from 'aws-amplify/auth'; import { fetchAuthSession, getCurrentUser, signInWithRedirect, signOut } from 'aws-amplify/auth';
import { deleteAllScannedHistories } from '../api/qrCodeAPI'; // Import the API function import { deleteAllScannedHistories, getUserInfo } from '../api/qrCodeAPI'; // Import the API function
import { Buffer } from 'buffer'; import { Buffer } from 'buffer';
import { Ionicons } from '@expo/vector-icons';
function SignOutButton() { function SignOutButton() {
const { signOut } = useAuthenticator(); const { signOut } = useAuthenticator();
@@ -22,6 +23,17 @@ const handleSignInWithRedirect = async () => {
const SettingsScreen: React.FC = () => { const SettingsScreen: React.FC = () => {
const { userAttributes } = useFetchUserAttributes(); const { userAttributes } = useFetchUserAttributes();
const [googleAccessToken, setGoogleAccessToken] = useState<string | null>(null); const [googleAccessToken, setGoogleAccessToken] = useState<string | null>(null);
const [userEmail, setUserEmail] = useState<string | null>(null);
const fetchUserEmail = async () => {
try {
console.log('fetchUserEmail triggered');
const userInfo = await getUserInfo();
setUserEmail(userInfo.email); // Assuming userInfo has an email property
} catch (error) {
console.error('Error fetching user email:', error);
}
};
useEffect(() => { useEffect(() => {
const getGoogleAccessToken = async () => { const getGoogleAccessToken = async () => {
@@ -95,6 +107,10 @@ const SettingsScreen: React.FC = () => {
} }
}, [userAttributes]); }, [userAttributes]);
useEffect(() => {
fetchUserEmail();
}, []);
const handleLinkPress = (url: string) => { const handleLinkPress = (url: string) => {
Linking.openURL(url); Linking.openURL(url);
}; };
@@ -108,28 +124,56 @@ const SettingsScreen: React.FC = () => {
} }
}; };
const handleSignOut = () => {
Alert.alert('Confirm Sign Out', 'Are you sure you want to sign out?', [
{ text: 'Cancel', style: 'cancel' },
{ text: 'Sign Out', onPress: () => signOut() }
]);
};
const handleDeleteAllEmails = () => {
Alert.alert('Confirm Delete', 'Are you sure you want to delete all emails?', [
{ text: 'Cancel', style: 'cancel' },
{ text: 'Delete', onPress: () => console.log('Delete all emails') }
]);
};
return ( return (
<View style={styles.container}> <View style={styles.container}>
<Text style={styles.header}>Settings</Text> <Text style={styles.header}>Settings</Text>
{/* Profile Section */} {/* Profile Section */}
<View style={styles.section}> <View style={styles.section}>
<Text style={styles.sectionTitle}>Profile</Text> <View style={styles.profileContainer}>
{userAttributes ? ( <Ionicons name="person-circle" size={60} color="#f41c87" style={styles.profileIcon} />
<View> <Text style={styles.userName}>Hello, {userAttributes?.name || 'Unknown User'}</Text>
<Text style={styles.userName}>Hello, {userAttributes.name || 'Unknown User'}</Text>
{googleAccessToken && (
<Text>Google Access Token: {googleAccessToken.substring(0, 10)}...</Text>
)}
<SignOutButton />
</View> </View>
{userAttributes ? (
<TouchableOpacity style={styles.logoutButton} onPress={handleSignOut}>
<Ionicons name="log-out-outline" size={24} color="#fff" style={styles.buttonIcon} />
<Text style={styles.logoutButtonText}>Log Out</Text>
</TouchableOpacity>
) : ( ) : (
<TouchableOpacity style={styles.loginButton} onPress={handleSignInWithRedirect}> <TouchableOpacity style={styles.loginButton} onPress={handleSignInWithRedirect}>
<Ionicons name="log-in-outline" size={24} color="#fff" style={styles.buttonIcon} />
<Text style={styles.loginButtonText}>Log In</Text> <Text style={styles.loginButtonText}>Log In</Text>
</TouchableOpacity> </TouchableOpacity>
)} )}
</View> </View>
<View style={styles.divider} />
{/* Email Section */}
<View style={styles.section}>
<View style={styles.emailRow}>
<Text style={styles.sectionTitle}>Email: </Text>
<Text style={styles.userEmail}>{userEmail || 'Loading...'}</Text>
</View>
<TouchableOpacity style={styles.deleteAllButton} onPress={handleDeleteAllEmails}>
<Ionicons name="trash-outline" size={24} color="#fff" style={styles.buttonIcon} />
<Text style={styles.deleteAllButtonText}>Delete All Email</Text>
</TouchableOpacity>
</View>
<View style={styles.divider} /> <View style={styles.divider} />
@@ -137,6 +181,7 @@ const SettingsScreen: React.FC = () => {
<View style={styles.section}> <View style={styles.section}>
<Text style={styles.sectionTitle}>History & Bookmarks</Text> <Text style={styles.sectionTitle}>History & Bookmarks</Text>
<TouchableOpacity style={styles.deleteAllButton} onPress={handleDeleteAllHistories}> <TouchableOpacity style={styles.deleteAllButton} onPress={handleDeleteAllHistories}>
<Ionicons name="trash-outline" size={24} color="#fff" style={styles.buttonIcon} />
<Text style={styles.deleteAllButtonText}>Delete All History</Text> <Text style={styles.deleteAllButtonText}>Delete All History</Text>
</TouchableOpacity> </TouchableOpacity>
</View> </View>
@@ -185,27 +230,60 @@ const styles = StyleSheet.create({
color: '#000', color: '#000',
marginBottom: 10, marginBottom: 10,
}, },
profileContainer: {
flexDirection: 'row',
alignItems: 'center',
backgroundColor: '#ffe6f0',
padding: 15,
borderRadius: 15,
},
profileIcon: {
marginRight: 15,
},
userName: { userName: {
fontSize: 18,
color: '#f41c87',
fontWeight: 'bold',
},
logoutButton: {
backgroundColor: '#ff69b4',
borderRadius: 25,
paddingVertical: 10,
paddingHorizontal: 20,
alignItems: 'center',
justifyContent: 'center',
alignSelf: 'flex-start',
marginVertical: 10,
flexDirection: 'row',
},
logoutButtonText: {
color: '#fff',
fontSize: 16, fontSize: 16,
color: '#000',
marginBottom: 10,
}, },
loginButton: { loginButton: {
flexDirection: 'row',
backgroundColor: '#ff69b4', backgroundColor: '#ff69b4',
paddingVertical: 8, paddingVertical: 10,
paddingHorizontal: 20, paddingHorizontal: 20,
borderRadius: 20, borderRadius: 25,
alignItems: 'center', alignItems: 'center',
justifyContent: 'center', justifyContent: 'center',
alignSelf: 'flex-start', alignSelf: 'flex-start',
}, },
loginButtonText: { loginButtonText: {
color: '#000', color: '#fff',
fontSize: 16, fontSize: 16,
marginLeft: 10,
},
userEmail: {
fontSize: 16,
color: '#000',
marginBottom: 10,
}, },
deleteAllButton: { deleteAllButton: {
backgroundColor: '#ff0000', // Red color flexDirection: 'row',
borderRadius: 25, // Round button backgroundColor: '#ff0000',
borderRadius: 25,
paddingVertical: 10, paddingVertical: 10,
paddingHorizontal: 20, paddingHorizontal: 20,
alignItems: 'center', alignItems: 'center',
@@ -217,12 +295,21 @@ const styles = StyleSheet.create({
color: '#fff', color: '#fff',
fontSize: 16, fontSize: 16,
fontWeight: 'bold', fontWeight: 'bold',
marginLeft: 10,
},
buttonIcon: {
marginRight: 10,
}, },
divider: { divider: {
height: 1, height: 1,
backgroundColor: '#ccc', backgroundColor: '#ccc',
marginVertical: 20, marginVertical: 20,
}, },
emailRow: {
flexDirection: 'row',
alignItems: 'center', // Align the text vertically in the center
marginBottom: 10, // Add some spacing below the row
},
linkText: { linkText: {
fontSize: 16, fontSize: 16,
color: '#0000ff', color: '#0000ff',
@@ -234,7 +321,6 @@ const styles = StyleSheet.create({
color: '#aaa', color: '#aaa',
marginTop: 20, marginTop: 20,
}, },
}); });
export default SettingsScreen; export default SettingsScreen;