diff --git a/src/components/sideMenu/container/sideMenuContainer.js b/src/components/sideMenu/container/sideMenuContainer.tsx similarity index 59% rename from src/components/sideMenu/container/sideMenuContainer.js rename to src/components/sideMenu/container/sideMenuContainer.tsx index 92fec2a23..f6e4c9961 100644 --- a/src/components/sideMenu/container/sideMenuContainer.js +++ b/src/components/sideMenu/container/sideMenuContainer.tsx @@ -1,4 +1,5 @@ -import React from 'react'; +import React, { useEffect } from 'react'; +import { Alert } from 'react-native' import { useDispatch, useSelector } from 'react-redux'; // Actions @@ -7,9 +8,16 @@ import { setInitPosts, setFeedPosts } from '../../../redux/actions/postsAction'; // Component import SideMenuView from '../view/sideMenuView'; +import { useDrawerStatus } from '@react-navigation/drawer'; +import { updateCurrentAccount } from '../../../redux/actions/accountAction'; +import { getUser } from '../../../providers/hive/dhive'; +import bugsnapInstance from '../../../config/bugsnag'; const SideMenuContainer = ({ navigation }) => { const dispatch = useDispatch(); + const drawerStatus = useDrawerStatus(); + + const isLoggedIn = useSelector((state) => state.application.isLoggedIn); const currentAccount = useSelector((state) => state.account.currentAccount); @@ -17,6 +25,34 @@ const SideMenuContainer = ({ navigation }) => { (state) => state.ui.isVisibleAccountsBottomSheet, ); + + useEffect(()=>{ + if(drawerStatus === 'open'){ + //update profile on drawer open + _updateUserData(); + } + + }, [drawerStatus]) + + + //fetches and update user data + const _updateUserData = async () => { + try{ + if(currentAccount?.username){ + let accountData = await getUser(currentAccount.username); + if(accountData){ + dispatch(updateCurrentAccount({...currentAccount, ...accountData})) + } + } + + } catch(err){ + console.warn("failed to update user data") + bugsnapInstance.notify(err); + } + + } + + const _navigateToRoute = (route = null) => { if (route) { navigation.navigate(route);