Profile avatar cloud upload + test bundle ID
- Profile avatar now uploads to MinIO cloud storage via /auth/avatar endpoint - Added loading indicator (ActivityIndicator) during avatar upload - Avatar loads from cloud URL (user.avatarUrl) first, with SecureStore fallback - Changed iOS bundleIdentifier to com.serter2069.wellnuo.test (test account)
This commit is contained in:
parent
5e0b38748b
commit
5c8c3665da
2
app.json
2
app.json
@ -10,7 +10,7 @@
|
|||||||
"newArchEnabled": true,
|
"newArchEnabled": true,
|
||||||
"ios": {
|
"ios": {
|
||||||
"supportsTablet": true,
|
"supportsTablet": true,
|
||||||
"bundleIdentifier": "com.wellnuo.BluetoothScanner",
|
"bundleIdentifier": "com.serter2069.wellnuo.test",
|
||||||
"appleTeamId": "UHLZD54ULZ",
|
"appleTeamId": "UHLZD54ULZ",
|
||||||
"deploymentTarget": "16.0",
|
"deploymentTarget": "16.0",
|
||||||
"infoPlist": {
|
"infoPlist": {
|
||||||
|
|||||||
@ -7,7 +7,9 @@ import {
|
|||||||
Alert,
|
Alert,
|
||||||
Image,
|
Image,
|
||||||
ScrollView,
|
ScrollView,
|
||||||
|
ActivityIndicator,
|
||||||
} from 'react-native';
|
} from 'react-native';
|
||||||
|
import { api } from '@/services/api';
|
||||||
import { Ionicons } from '@expo/vector-icons';
|
import { Ionicons } from '@expo/vector-icons';
|
||||||
import { SafeAreaView } from 'react-native-safe-area-context';
|
import { SafeAreaView } from 'react-native-safe-area-context';
|
||||||
import * as SecureStore from 'expo-secure-store';
|
import * as SecureStore from 'expo-secure-store';
|
||||||
@ -61,6 +63,7 @@ export default function ProfileScreen() {
|
|||||||
|
|
||||||
// Avatar
|
// Avatar
|
||||||
const [avatarUri, setAvatarUri] = useState<string | null>(null);
|
const [avatarUri, setAvatarUri] = useState<string | null>(null);
|
||||||
|
const [isUploadingAvatar, setIsUploadingAvatar] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadAvatar();
|
loadAvatar();
|
||||||
@ -68,6 +71,13 @@ export default function ProfileScreen() {
|
|||||||
|
|
||||||
const loadAvatar = async () => {
|
const loadAvatar = async () => {
|
||||||
try {
|
try {
|
||||||
|
// First try to get cloud URL from user profile
|
||||||
|
if (user?.avatarUrl) {
|
||||||
|
setAvatarUri(user.avatarUrl);
|
||||||
|
await SecureStore.setItemAsync('userAvatar', user.avatarUrl);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Fallback to cached local avatar
|
||||||
const uri = await SecureStore.getItemAsync('userAvatar');
|
const uri = await SecureStore.getItemAsync('userAvatar');
|
||||||
if (uri) {
|
if (uri) {
|
||||||
setAvatarUri(uri);
|
setAvatarUri(uri);
|
||||||
@ -98,9 +108,30 @@ export default function ProfileScreen() {
|
|||||||
// Optimize image: resize to 400x400 and compress
|
// Optimize image: resize to 400x400 and compress
|
||||||
const optimizedUri = await optimizeAvatarImage(originalUri);
|
const optimizedUri = await optimizeAvatarImage(originalUri);
|
||||||
|
|
||||||
|
// Show optimistic update immediately
|
||||||
setAvatarUri(optimizedUri);
|
setAvatarUri(optimizedUri);
|
||||||
await SecureStore.setItemAsync('userAvatar', optimizedUri);
|
|
||||||
|
// Upload to cloud storage
|
||||||
|
setIsUploadingAvatar(true);
|
||||||
|
try {
|
||||||
|
const response = await api.updateProfileAvatar(optimizedUri);
|
||||||
|
if (response.ok && response.data?.avatarUrl) {
|
||||||
|
// Use cloud URL instead of local
|
||||||
|
setAvatarUri(response.data.avatarUrl);
|
||||||
|
await SecureStore.setItemAsync('userAvatar', response.data.avatarUrl);
|
||||||
toast.success('Avatar updated');
|
toast.success('Avatar updated');
|
||||||
|
} else {
|
||||||
|
// Fallback to local storage if cloud upload fails
|
||||||
|
await SecureStore.setItemAsync('userAvatar', optimizedUri);
|
||||||
|
toast.error(response.error?.message || 'Cloud upload failed, saved locally');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Avatar upload error:', error);
|
||||||
|
await SecureStore.setItemAsync('userAvatar', optimizedUri);
|
||||||
|
toast.error('Upload failed, saved locally');
|
||||||
|
} finally {
|
||||||
|
setIsUploadingAvatar(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -180,14 +211,24 @@ export default function ProfileScreen() {
|
|||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
style={styles.avatarContainer}
|
style={styles.avatarContainer}
|
||||||
onPress={handleAvatarChange}
|
onPress={handleAvatarChange}
|
||||||
|
disabled={isUploadingAvatar}
|
||||||
>
|
>
|
||||||
{avatarUri ? (
|
{avatarUri ? (
|
||||||
<Image source={{ uri: avatarUri }} style={styles.avatarImage} />
|
<Image source={{ uri: avatarUri }} style={styles.avatarImage} />
|
||||||
) : (
|
) : (
|
||||||
<Text style={styles.avatarText}>{userInitial}</Text>
|
<Text style={styles.avatarText}>{userInitial}</Text>
|
||||||
)}
|
)}
|
||||||
|
{isUploadingAvatar && (
|
||||||
|
<View style={styles.avatarLoadingOverlay}>
|
||||||
|
<ActivityIndicator size="large" color={AppColors.white} />
|
||||||
|
</View>
|
||||||
|
)}
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
<TouchableOpacity style={styles.avatarEditBadge} onPress={handleAvatarChange}>
|
<TouchableOpacity
|
||||||
|
style={styles.avatarEditBadge}
|
||||||
|
onPress={handleAvatarChange}
|
||||||
|
disabled={isUploadingAvatar}
|
||||||
|
>
|
||||||
<Ionicons name="camera" size={14} color={AppColors.white} />
|
<Ionicons name="camera" size={14} color={AppColors.white} />
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
</View>
|
</View>
|
||||||
@ -339,6 +380,13 @@ const styles = StyleSheet.create({
|
|||||||
fontWeight: FontWeights.bold,
|
fontWeight: FontWeights.bold,
|
||||||
color: AppColors.white,
|
color: AppColors.white,
|
||||||
},
|
},
|
||||||
|
avatarLoadingOverlay: {
|
||||||
|
...StyleSheet.absoluteFillObject,
|
||||||
|
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
||||||
|
borderRadius: AvatarSizes.xl / 2,
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
},
|
||||||
avatarEditBadge: {
|
avatarEditBadge: {
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
bottom: 0,
|
bottom: 0,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user