-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathApp.js
96 lines (84 loc) · 2.13 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
86
87
88
89
90
91
92
93
94
import React from 'react'
import { StyleSheet, Text, View } from 'react-native'
import Amplify from '@aws-amplify/core'
import API, { graphqlOperation } from '@aws-amplify/api'
import { withAuthenticator } from 'aws-amplify-react-native'
import config from './src/aws-exports'
import Posts from './src/components/Posts'
import { listPosts } from './src/GraphQL/GraphQL'
// configure the app with Amplify
Amplify.configure(config)
class App extends React.Component {
state = {
posts: '',
refreshing: false,
}
componentDidMount = async () => {
this.timerID = await setInterval(() => {
this.countPosts()
},
1000)
}
componentWillUnmount = async () => {
await clearInterval(this.timerID)
}
// Get number of posts from the Upload Component
countPosts = async () => {
try {
const graphqldata = await API.graphql(graphqlOperation(listPosts))
this.setState({
posts: graphqldata.data.listPosts.items, postContent: ''
})
// console.log(this.state.posts.length)
}
catch (err) {
console.log('error: ', err)
}
}
render() {
return (
<View style={{ flex: 1 }}>
<View style={styles.container}>
{/* Number of entries */}
<View style={{ flex: 1, alignItems: 'center', marginRight: 20 }}>
<Text style={styles.textStyle}>
ENTRIES
</Text>
<Text style={styles.textTimerStyle}>
{this.state.posts.length}
</Text>
</View>
</View>
<Posts countPosts={this.countPosts} />
</View>
)
}
}
export default withAuthenticator(
App, {
// Render a sign out button once logged in
includeGreetings: true}
)
const styles = StyleSheet.create({
container: {
flex: 0.10,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'flex-start',
borderBottomWidth: 1,
borderBottomColor: '#a8abaf',
},
textStyle: {
fontSize: 18,
color: '#3d4147',
},
textTimerStyle: {
fontSize: 18,
color: '#5017ae',
fontWeight: 'bold'
},
lockIconStyle: {
color: '#5017ae',
fontSize: 45,
}
})