-
Notifications
You must be signed in to change notification settings - Fork 319
/
App.tsx
75 lines (72 loc) · 2.04 KB
/
App.tsx
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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* Generated with the TypeScript template
* https://github.com/react-native-community/react-native-template-typescript
*
* @format
*/
import React, { useEffect, useRef } from 'react';
import { StyleSheet, YellowBox, AppState } from 'react-native';
import { Provider } from 'react-redux';
import SplashScreen from 'react-native-splash-screen'
import { PersistGate } from 'redux-persist/integration/react';
import RootStackNavigation from './src/navigations';
import { persistor, store } from './src/store';
import { getImageClass, convertToFirebaseDatabasePathName } from './src/utils';
import { firestore, database } from 'firebase';
import { Post } from './src/reducers/postReducer';
YellowBox.ignoreWarnings([
'',
]);
const App = () => {
const myUsername = store.getState().user.user?.userInfo?.username
const ref = useRef<{ itv: NodeJS.Timeout }>({
itv: setInterval(() => { }, 3000)
})
useEffect(() => {
clearInterval(ref.current.itv)
SplashScreen.hide()
// const db = firestore()
// db.collection('posts').get().then(rs => {
// rs.docs.map(doc => {
// const post: Post = doc.data() as Post
// if (post.source) {
// const tasks = post.source.map(async x => {
// const className = await getImageClass(x.uri)
// return className
// })
// Promise.all(tasks).then(classes => {
// doc.ref.update({
// labels: classes
// })
// })
// }
// })
// })
if (myUsername) {
// limit functions quota
ref.current.itv = setInterval(() => {
if (AppState.currentState === 'active') {
database().ref(`/online/${convertToFirebaseDatabasePathName(myUsername)}`)
.update({
last_online: new Date().getTime(),
status: 1
})
}
}, 60000)
}
}, [])
console.log("render")
return (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<RootStackNavigation />
</PersistGate>
</Provider>
);
};
const styles = StyleSheet.create({
});
export default App;