Files
EMI-ExpoAPP/components/GroupCard.js
T
2026-02-20 19:25:38 -05:00

106 lines
3.6 KiB
JavaScript

import React, { useState, useEffect } from 'react';
import { Text, StyleSheet, View } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialIcons';
import { List, IconButton, Card, Chip, Badge } from 'react-native-paper';
import API from './../API.js';
import { useNavigation } from '@react-navigation/native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import FollowButton from './basics/FollowButton.js';
import ProfilePhotoCircle from './ProfilePhotoCircle.js';
const DefaultPhoto = "https://social.emmint.com/uploads/e6f9be6d665dc43417701bf16a90122c.png";
const storeName = async (key, value) => {
try {
const jsonValue = JSON.stringify(value)
await AsyncStorage.setItem('Name_' + key, jsonValue)
} catch (e) {
}
}
const getName = async (key) => {
try {
const value = await AsyncStorage.getItem('Name_' + key)
if (value !== null) {
return JSON.parse(value);
}
} catch (e) {
return []
}
}
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 (safeProfileObj._id) return 0;
let cacheProfile = await getName(profileid);
if (cacheProfile && cacheProfile.profile) setProfile(cacheProfile);
let p = await API.getUserProfile(profileid).catch(() => { return {} });
if (subscribed) setProfile(p);
storeName(profileid, p);
};
getData();
return () => {
subscribed = false;
}
}, [profileid]);
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: safeProfile._id })
}
return (
<Card style={styles.content}>
<Card.Content style={{padding:0}}>
<IconButton icon={icon} style={{
position: "absolute",
right: 0,
top: 0,
}} />
<List.Item
title={<ProfilePhotoCircle profileid={profile._id} />}
description={safeProfileObjInfo.description || ""}
//left={props => <List.Icon {...props} icon={icon} />}
titleStyle={{fontWeight:"bold", fontSize:20}}
descriptionStyle={{}}
onPress={onPress}
descriptionNumberOfLines={4}
style={{padding:0}}
/>
</Card.Content>
</Card>
);
}
export default React.memo(ProfileCard);
const styles = StyleSheet.create({
content: {
margin: 0,
padding: 0,
borderRadius: 0,
marginBottom: 2,
},
centerItems: {
justifyContent: 'center',
alignItems: 'center',
}
});