BE check for subscription on useEffect

This commit is contained in:
aeroreyna
2022-11-18 10:58:18 -05:00
parent 193284e00d
commit 4e1112fbf4
2 changed files with 26 additions and 10 deletions

View File

@@ -33,24 +33,31 @@ let Feed = ({ navigation, route }) => {
console.log("Render Feed");
useEffect(async () => {
let loggedIn = await API.isLoggedIn();
if(!loggedIn) return navigation.reset({
if (!loggedIn) return navigation.reset({
index: 0,
routes: [{ name: 'Login' }],
});
});
if (route.params && route.params.profileid) {
navigation.navigate('Profile', { profileid: route.params.profileid })
return navigation.navigate('Profile', { profileid: route.params.profileid })
}
let subscribed = true;
API.getMe().then((me) => {
GlobalState.me = me;
if (subscribed)
GlobalState.me = me;
});
console.log("Feed from cache")
let cacheFeed = await getFeed() || [];
if(cacheFeed.length) setPosts(cacheFeed);
if (cacheFeed.length && subscribed) setPosts(cacheFeed);
console.log("Feed from server")
let posts = await API.getPosts();
setPosts(posts);
storeFeed(posts);
if (subscribed) {
setPosts(posts);
storeFeed(posts);
}
console.log("Feed, end useEffect")
return () => {
subscribed = false;
}
}, [route.params]);
const renderPost = (({ item }) => {
if (item.nonOrganicType === 'PopularUsers' || item.nonOrganicType === 'PopularGroups')