Refresh profile from server and return after update

This commit is contained in:
Adolfo Reyna
2026-02-20 22:10:44 -05:00
parent ffb8f9bec5
commit cc9ca1d075
2 changed files with 26 additions and 10 deletions

View File

@@ -256,16 +256,25 @@ let Profile = ({ navigation, route }) => {
tag,
});
setLoading(true);
API.getPosts(route.params.profileid).then((data) => {
Promise.all([
API.getUserProfile(route.params.profileid, true),
API.getPosts(route.params.profileid),
]).then(([profileObj, data]) => {
const nextProfile = profileObj && profileObj._id ? profileObj : {};
const profileData = nextProfile.profile || {};
const safePosts = Array.isArray(data) ? data : [];
setProfile(nextProfile);
navigation.setOptions({ title: (profileData.firstName || "") + " " + (profileData.lastName || "") });
setPosts(safePosts);
storeProfilePosts(route.params.profileid, safePosts);
setLoading(false);
logProfile('refresh:end', {
profileid: route.params.profileid,
count: safePosts.length,
cached: true,
cached: false,
});
}).catch(() => {
setLoading(false);
});
}}
/> :

View File

@@ -10,10 +10,12 @@ import { useSnapshot } from 'valtio';
import GlobalState from '../contexts/GlobalState.js';
import API from "../API.js";
import * as ImagePicker from 'expo-image-picker';
import { useNavigation } from '@react-navigation/native';
let ProfileSettings = () => {
const navigation = useNavigation();
const gState = useSnapshot(GlobalState);
const viewer = gState.me;
const viewerProfile = viewer?.profile || {};
@@ -64,8 +66,10 @@ let ProfileSettings = () => {
setphotoUrl(newPhotoURL);
if (!GlobalState.me.profile) GlobalState.me.profile = {};
GlobalState.me.profile.photo = newPhotoURL;
await updateProfile({ photo: newPhotoURL });
await updateProfile({ photo: newPhotoURL }, false);
setUpdateKey((k) => k + 1);
} else {
alert("Could not upload photo. Please try another image.");
}
setPhoto(null);
setUploading(false);
@@ -74,17 +78,17 @@ let ProfileSettings = () => {
const handleUploadPhoto = async (photo) => {
console.log(photo)
if (!photo) return;
if (!photo) return '';
const uri =
Platform.OS === "android"
? photo.uri
: photo.uri.replace("file://", "");
console.log(uri);
const filename = photo.uri.split("/").pop();
const filename = photo.uri.split("/").pop() || "image.jpg";
const match = /\.(\w+)$/.exec(filename);
const ext = match?.[1];
const type = match ? `image/${match[1]}` : `image`;
const ext = (match?.[1] || "jpg").toLowerCase();
const type = ext === "heic" || ext === "heif" ? "image/heic" : `image/${ext}`;
const formData = new FormData();
formData.append("banner", {
uri,
@@ -101,7 +105,7 @@ let ProfileSettings = () => {
.then((res) => res.json())
.then((data) => {
console.log(data);
return data.fileName;
return data?.fileName || '';
});
console.log(uploadedFile);
} catch (err) {
@@ -111,7 +115,7 @@ let ProfileSettings = () => {
return uploadedFile;
};
let updateProfile = async (overrides = {}) => {
let updateProfile = async (overrides = {}, goBackAfter = true) => {
let currentProfile = {};
let currentData = {};
try {
@@ -156,6 +160,9 @@ let ProfileSettings = () => {
}
console.log(r);
setUpdateKey((k) => k + 1);
if (goBackAfter) {
navigation.goBack();
}
}
return (
@@ -219,7 +226,7 @@ let ProfileSettings = () => {
</View>
<Button
mode="contained"
onPress={updateProfile}
onPress={() => updateProfile({}, true)}
buttonColor="#c44d56"
textColor="#ffffff"
style={{ marginTop: 8 }}