Skip to content

Commit

Permalink
working async
Browse files Browse the repository at this point in the history
  • Loading branch information
developer-ayan committed Apr 30, 2022
1 parent 2042a65 commit d8526e1
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 62 deletions.
34 changes: 18 additions & 16 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,33 @@ export default function App() {
const {setUser , user} = useContext(AuthContext);
const [save, setSave] = React.useState({});
const uid = useSelector(state => state.user);
const [loading, setLoading] = useState(true);
const [loading, setLoading] = useState(false);

const get_data = async () => {
setLoading(true);
// const get_data = async () => {
// setLoading(true);

try {
const value = await AsyncStorage.getItem('uid');
if (value !== 'null') {
setSave(JSON.parse(value));
}
} catch (error) {
// Error retrieving data
}
setLoading(false);
};
// try {
// const value = await AsyncStorage.getItem('uid');
// if (value !== 'null') {
// setSave(JSON.parse(value));
// }
// } catch (error) {
// // Error retrieving data
// }
// setLoading(false);
// };

React.useEffect(() => {
get_data()
// get_data()
setTimeout(() => {
SplashScreen.hide()
}, 2000);
}, []);

setUser(save === null ? uid : save)
console.log("redux ",save)
// setUser(save === null ? uid : save)

console.log(" app .js state ",user)

// console.log("async ",save === null ? uid : save)
return loading ? (
<ActivityIndicator
Expand Down
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import {name as appName} from './app.json';
import store from './src/redux/Index';
import {AuthProvider} from './src/context/Auth';
const Root = () => (
<AuthProvider>
<Provider store={store}>
<Provider store={store}>
<AuthProvider>
<App />
</Provider>
</AuthProvider>
</AuthProvider>
</Provider>
);

AppRegistry.registerComponent(appName, () => Root);
3 changes: 0 additions & 3 deletions src/category/Categories_detail/Categories_detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export default function Categories_detail({route, navigation}) {
const [submited, setSubmited] = useState([]);
const {user} = useContext(AuthContext);

console.log('ZIPCODE ', LIKE);

const onShare = async () => {
try {
Expand Down Expand Up @@ -103,11 +102,9 @@ export default function Categories_detail({route, navigation}) {
});
}, []);

console.log('submited ', submited);

const [show, setshow] = React.useState(USER_LIKE !== user?.USER_ID);

// console.log('USER_LIKE ', USER_LIKE);

const toggle = () => {
setshow(!show);
Expand Down
1 change: 0 additions & 1 deletion src/category/Get_offer/Get_offer.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ function Get_offer() {
}, 100);
});

// console.log('unseen ', unseen);

firestore()
.collection('Bids')
Expand Down
18 changes: 6 additions & 12 deletions src/comonents/Bottom/BottomNav.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useContext} from 'react';
import React, {useContext, useEffect} from 'react';
import {createMaterialBottomTabNavigator} from '@react-navigation/material-bottom-tabs';
import AntDesign from 'react-native-vector-icons/AntDesign';
import Fontisto from 'react-native-vector-icons/Fontisto';
Expand All @@ -18,19 +18,13 @@ import firestore from '@react-native-firebase/firestore';
import {ActivityIndicator} from 'react-native';

export default function BottomNav() {
const state = useSelector(state => state.user);
// const state = useSelector(state => state.user);
const {messageCounting} = useContext(AuthContext);
const [loading, setLoading] = React.useState(true);

React.useEffect(() => {
try {
const userDetail = JSON.stringify(state);
AsyncStorage.setItem('userData', userDetail);
} catch (e) {
// saving error
}
const {user} = useContext(AuthContext)


useEffect(() => {

firestore()
.collection('Category')
Expand All @@ -51,8 +45,8 @@ export default function BottomNav() {
.map(e => e.data())
.filter(function (item) {
return (
item.user1.uid === state?.USER_ID ||
item.user2.uid === state?.USER_ID
item.user1.uid === user?.USER_ID ||
item.user2.uid === user?.USER_ID
);
}),
setLoading(false)
Expand Down
6 changes: 3 additions & 3 deletions src/comonents/CustomDrawer/CustomDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ function CustomDrawer(props) {
const {user, setUser} = useContext(AuthContext);
const removeData = async () => {
await AsyncStorage.removeItem('uid');
setUser(null);
// setUser({})
// setUser(null)

RNRestart.Restart();
};

React.useEffect(() => {
Expand All @@ -38,7 +38,7 @@ function CustomDrawer(props) {
.onSnapshot(e => {
setData(e.data());
});
}, [user?.USER_ID]);
}, [user?.USER_ID , removeData]);

return (
<View style={{flex: 1}}>
Expand Down
37 changes: 37 additions & 0 deletions src/context/Auth.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, {createContext, useCallback, useEffect, useState} from 'react';
import firestore from '@react-native-firebase/firestore';
import AsyncStorage from '@react-native-async-storage/async-storage';

export const AuthContext = createContext({});
export const AuthProvider = props => {
Expand All @@ -19,6 +20,42 @@ export const AuthProvider = props => {
});
});

// const get_data = async () => {

// try {
// const value = await AsyncStorage.getItem('uid');
// // console.log("Async strogare" ,JSON.parse(value));
// // setSave(JSON.parse(value))

// if (value !== 'null' || value !== null) {
// setSave(JSON.parse(value));
// }
// } catch (error) {
// // Error retrieving data
// }
// };
const get_data = async () => {

console.log('ayan')

// try {
const value = await AsyncStorage.getItem('uid');
// console.log("Async strogare" ,JSON.parse(value));
// setSave(JSON.parse(value))

if (value !== 'null' || value !== null) {
setUser(JSON.parse(value));
}
// } catch (error) {
// // Error retrieving data
// }
};
useEffect(() => {


get_data();
}, [get_data]);

return (
<AuthContext.Provider
value={{
Expand Down
25 changes: 2 additions & 23 deletions src/redux/actions/authAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ const sign_in = user => {
.doc(res.user.uid)
.onSnapshot(documentSnapshot => {
dispatch({type: 'GETUSER', user: documentSnapshot.data()});
console.log('In redux ', documentSnapshot.data());
resolve((user = documentSnapshot.data()));
});
})
Expand All @@ -64,6 +63,7 @@ function create_ads(user) {
return dispatch => {
const User_data = user;


firestore()
.collection(`Category`)
.add({
Expand All @@ -84,25 +84,4 @@ function create_ads(user) {
};
}

function all_ads() {
const [save, setSave] = React.useState({});
return dispatch => {
const get_data = async () => {
try {
const userDetail = await AsyncStorage.getItem('userData');
const check = JSON.parse(userDetail);

check != {} ? setSave(check) : null;
dispatch({type: 'DATA', data: check});
} catch (e) {
// error reading value
console.log(e);
}
};

React.useEffect(() => {
get_data();
}, []);
};
}
export {signUp, sign_in, create_ads, all_ads};
export {signUp, sign_in, create_ads,};

0 comments on commit d8526e1

Please sign in to comment.