Skip to content

Commit

Permalink
Merge pull request #2762 from ecency/nt/drawer-user-update
Browse files Browse the repository at this point in the history
update current user data on drawer open
  • Loading branch information
feruzm authored Sep 22, 2023
2 parents 16545d8 + 1167022 commit e915dcb
Showing 1 changed file with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -7,16 +8,51 @@ 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);
const isVisibleAccountsBottomSheet = useSelector(
(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);
Expand Down

0 comments on commit e915dcb

Please sign in to comment.