Gracefully handle backend failures in Expo app
This commit is contained in:
@@ -30,12 +30,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 && subscribed) setProfile(cacheProfile);
|
||||
let p = await API.getUserProfile(profileid).catch(() => { return {} });
|
||||
@@ -48,13 +52,13 @@ 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;
|
||||
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;
|
||||
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 (
|
||||
@@ -63,11 +67,11 @@ let ProfileCard = ({ profileid, hideIcon, profileObj }) => {
|
||||
<Avatar.Image size={150} source={{ uri: photoUrl }} />
|
||||
<Title onPress={onPress} numberOfLines={1}>
|
||||
<Text>
|
||||
{profile.profile && profile.profile.firstName} {profile.profile && profile.profile.lastName}
|
||||
{safeProfileInfo.firstName} {safeProfileInfo.lastName}
|
||||
</Text>
|
||||
</Title>
|
||||
<Paragraph numberOfLines={2}>{profileObj.profile.description}</Paragraph>
|
||||
<FollowButton profile={profile} />
|
||||
<Paragraph numberOfLines={2}>{safeProfileObjInfo.description || ""}</Paragraph>
|
||||
<FollowButton profile={safeProfile} />
|
||||
</Card.Content>
|
||||
</Card>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user