Profile Cache and Profile Header Started
This commit is contained in:
@@ -1,21 +1,21 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Text, View, ScrollView, Button, StyleSheet } from 'react-native';
|
||||
import { Text, StyleSheet } from 'react-native';
|
||||
import Icon from 'react-native-vector-icons/MaterialIcons';
|
||||
import API from './../API.js';
|
||||
import { useNavigation } from '@react-navigation/native';
|
||||
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
|
||||
const storeName = async (key, value) => {
|
||||
try {
|
||||
const jsonValue = JSON.stringify(value)
|
||||
await AsyncStorage.setItem('Name_'+key, jsonValue)
|
||||
await AsyncStorage.setItem('Name_' + key, jsonValue)
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
|
||||
const getName = async (key) => {
|
||||
try {
|
||||
const value = await AsyncStorage.getItem('Name_'+key)
|
||||
const value = await AsyncStorage.getItem('Name_' + key)
|
||||
if (value !== null) {
|
||||
return JSON.parse(value);
|
||||
}
|
||||
@@ -24,25 +24,33 @@ const getName = async (key) => {
|
||||
}
|
||||
}
|
||||
|
||||
let UserName = ({profileid}) => {
|
||||
let UserName = ({ profileid }) => {
|
||||
let [profile, setProfile] = useState({});
|
||||
const navigation = useNavigation();
|
||||
|
||||
useEffect(async () => {
|
||||
let cacheProfile = await getName(profileid);
|
||||
if(cacheProfile && cacheProfile.profile) setProfile(cacheProfile);
|
||||
if (cacheProfile && cacheProfile.profile) setProfile(cacheProfile);
|
||||
let p = await API.getUserProfile(profileid).catch(() => { return {} });
|
||||
setProfile(p);
|
||||
storeName(profileid, p)
|
||||
}, [profileid]);
|
||||
|
||||
const onPress = ()=>{
|
||||
return navigation.navigate('Profile', { 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;
|
||||
|
||||
const onPress = () => {
|
||||
return navigation.navigate('Profile', { profileid })
|
||||
}
|
||||
|
||||
return (
|
||||
<Text onPress={onPress}>
|
||||
{profile.profile && profile.profile.firstName} {profile.profile && profile.profile.lastName}
|
||||
<Text style={{ paddingTop: 10 }}>
|
||||
<Icon name={icon} size={18} />
|
||||
</Text>
|
||||
<Text> {profile.profile && profile.profile.firstName} {profile.profile && profile.profile.lastName}</Text>
|
||||
|
||||
</Text>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user