Fix change profile photo

This commit is contained in:
Adolfo Reyna
2023-08-24 23:11:47 -04:00
parent 30ba1af902
commit c2f4a459c9

View File

@@ -22,26 +22,30 @@ let ProfileSettings = ()=>{
const [photoUrl, setphotoUrl] = React.useState(viewer.profile.photo); const [photoUrl, setphotoUrl] = React.useState(viewer.profile.photo);
const [updateKey, setUpdateKey] = React.useState(0); const [updateKey, setUpdateKey] = React.useState(0);
const [description, setDescription] = React.useState(viewer.profile.description); const [description, setDescription] = React.useState(viewer.profile.description);
const [uploading, setUploading] = React.useState(false);
const pickImage = async () => { const pickImage = async () => {
if(uploading) return;
// No permissions request is necessary for launching the image library // No permissions request is necessary for launching the image library
let result = await ImagePicker.launchImageLibraryAsync({ let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.Images, mediaTypes: ImagePicker.MediaTypeOptions.Images,
allowsEditing: true, allowsEditing: true,
aspect: [4, 3], aspect: [4, 3],
quality: 0.2, quality: 0.5,
//allowsMultipleSelection: true, //allowsMultipleSelection: true,
}); });
if (!result.canceled) { if (!result.canceled) {
setUploading(true);
setPhoto(result); setPhoto(result);
let newPhotoURL = await handleUploadPhoto(result.assets[0]); let newPhotoURL = await handleUploadPhoto(result.assets[0]);
if(newPhotoURL !== ""){ if(newPhotoURL !== ""){
setphotoUrl(newPhotoURL); setphotoUrl(newPhotoURL);
GlobalState.me.profile.photo = newPhotoURL; GlobalState.me.profile.photo = newPhotoURL;
viewer.profile.photo = newPhotoURL; updateProfile()
setUpdateKey(updateKey + 1); setUpdateKey(updateKey + 1);
} }
setPhoto(null); setPhoto(null);
setUploading(false);
} }
}; };
@@ -88,7 +92,7 @@ let ProfileSettings = ()=>{
GlobalState.me.profile.firstName = name; GlobalState.me.profile.firstName = name;
GlobalState.me.profile.lastName = lastName; GlobalState.me.profile.lastName = lastName;
GlobalState.me.profile.description = description; GlobalState.me.profile.description = description;
API.updateMyProfile(viewer.profile, viewer.data); API.updateMyProfile(GlobalState.me.profile, viewer.data);
setUpdateKey(updateKey+1); setUpdateKey(updateKey+1);
} }
@@ -130,7 +134,7 @@ let ProfileSettings = ()=>{
<RadioButton.Item value="en" label="English"/> <RadioButton.Item value="en" label="English"/>
</RadioButton.Group> </RadioButton.Group>
</View> </View>
<Button icon="photo" mode="outlined" onPress={pickImage} >{i18n.t("message.updatePhoto")}</Button> <Button icon="photo" mode="outlined" onPress={pickImage}>{!uploading ? i18n.t("message.updatePhoto"): "uploading"}</Button>
<Divider /> <Divider />
<View style={{paddingTop: 10}}> <View style={{paddingTop: 10}}>
<Text style={{fontSize:20, padding: 5, color:"#666"}}>Preview:</Text> <Text style={{fontSize:20, padding: 5, color:"#666"}}>Preview:</Text>