-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
85 lines (74 loc) · 2.61 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { useEffect } from "react";
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Alert, LogBox } from 'react-native';
// import ChatBot called DialogFlow
import { Dialogflow_V2 } from 'react-native-dialogflow';
import { dialogflowConfig } from "./dialogConfig";
// import netinfo to check online or offline
import { useNetInfo } from '@react-native-community/netinfo';
// import react Navigation
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
// import the screens
import Chat from './components/Chat';
import Start from './components/Start';
// Create the navigator
const Stack = createNativeStackNavigator();
// ignores error Message in Welcome Screen
LogBox.ignoreLogs(["AsyncStorage has been extracted from"]);
import { initializeApp } from "firebase/app";
import { getFirestore, disableNetwork, enableNetwork } from "firebase/firestore";
import { getStorage } from "firebase/storage";
const App = () => {
const connectionStatus = useNetInfo();
const dialogFlow = () => {
Dialogflow_V2.setConfiguration(
dialogflowConfig.client_email,
dialogflowConfig.private_key,
Dialogflow_V2.LANG_ENGLISH_US,
dialogflowConfig.project_id,
);
}
useEffect(() => {
dialogFlow();
if (connectionStatus.isConnected === false) {
Alert.alert("Connection lost!");
disableNetwork(db);
} else if (connectionStatus.isConnected === true) {
enableNetwork(db);
}
}, [connectionStatus.isConnected]);
const firebaseConfig = {
apiKey: process.env.EXPO_PUBLIC_FIREBASE_API_KEY,
authDomain: process.env.EXPO_PUBLIC_FIREBASE_AUTH_DOMAIN,
projectId: process.env.EXPO_PUBLIC_FIREBASE_PROJECT_ID,
storageBucket: process.env.EXPO_PUBLIC_FIREBASE_STORAGE_BUCKET,
messagingSenderId: process.env.EXPO_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
appId: process.env.EXPO_PUBLIC_FIREBASE_APP_ID
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
// Initialize Cloud Firestore and get a reference to the service
const db = getFirestore(app);
const storage = getStorage(app);
return (
<NavigationContainer>
<Stack.Navigator
initialRouteName="Home"
>
<Stack.Screen
name="Home"
component={Start}
/>
<Stack.Screen
name="Chat"
>
{props => <Chat isConnected={connectionStatus.isConnected} db={db} storage={storage} {...props} />}
</Stack.Screen>
</Stack.Navigator>
</NavigationContainer>
);
}
const styles = StyleSheet.create({
});
export default App;