mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-11-24 00:46:27 +03:00
Merge pull request #2762 from ecency/nt/drawer-user-update
update current user data on drawer open
This commit is contained in:
commit
e915dcb096
@ -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);
|
Loading…
Reference in New Issue
Block a user