Gracefully handle backend failures in Expo app
This commit is contained in:
@@ -31,12 +31,16 @@ const getName = async (key) => {
|
||||
|
||||
let ProfileCard = ({ profileid, hideIcon, profileObj }) => {
|
||||
let [profile, setProfile] = useState(profileObj || {});
|
||||
const safeProfile = profile || {};
|
||||
const safeProfileInfo = safeProfile.profile || {};
|
||||
const safeProfileObj = profileObj || {};
|
||||
const safeProfileObjInfo = safeProfileObj.profile || {};
|
||||
const navigation = useNavigation();
|
||||
|
||||
useEffect(() => {
|
||||
let subscribed = true;
|
||||
const getData = async () => {
|
||||
if (profileObj._id) return 0;
|
||||
if (safeProfileObj._id) return 0;
|
||||
let cacheProfile = await getName(profileid);
|
||||
if (cacheProfile && cacheProfile.profile) setProfile(cacheProfile);
|
||||
let p = await API.getUserProfile(profileid).catch(() => { return {} });
|
||||
@@ -49,14 +53,14 @@ let ProfileCard = ({ profileid, hideIcon, profileObj }) => {
|
||||
}
|
||||
}, [profileid]);
|
||||
|
||||
let icon = profile._id ? (!profile.isGroup ? "person-outline" : "group") : '';
|
||||
icon = icon === "person-outline" && profile.subscription && profile.subscription > (new Date() - 0) ? "assignment-ind" : icon;
|
||||
icon = icon === "group" && profile.isCourse ? "subscriptions" : icon;
|
||||
icon = icon === "group" && profile.isPrivate ? "screen-lock-portrait" : icon;
|
||||
let photoUrl = profile.profile.photo ? 'https://social.emmint.com/' + profile.profile.photo : DefaultPhoto;
|
||||
let icon = safeProfile._id ? (!safeProfile.isGroup ? "person-outline" : "group") : '';
|
||||
icon = icon === "person-outline" && safeProfile.subscription && safeProfile.subscription > (new Date() - 0) ? "assignment-ind" : icon;
|
||||
icon = icon === "group" && safeProfile.isCourse ? "subscriptions" : icon;
|
||||
icon = icon === "group" && safeProfile.isPrivate ? "screen-lock-portrait" : icon;
|
||||
let photoUrl = safeProfileInfo.photo ? 'https://social.emmint.com/' + safeProfileInfo.photo : DefaultPhoto;
|
||||
|
||||
const onPress = () => {
|
||||
return navigation.navigate('Profile', { profileid: profile._id })
|
||||
return navigation.navigate('Profile', { profileid: safeProfile._id })
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -70,7 +74,7 @@ let ProfileCard = ({ profileid, hideIcon, profileObj }) => {
|
||||
|
||||
<List.Item
|
||||
title={<ProfilePhotoCircle profileid={profile._id} />}
|
||||
description={profileObj.profile.description}
|
||||
description={safeProfileObjInfo.description || ""}
|
||||
//left={props => <List.Icon {...props} icon={icon} />}
|
||||
titleStyle={{fontWeight:"bold", fontSize:20}}
|
||||
descriptionStyle={{}}
|
||||
|
||||
Reference in New Issue
Block a user