/
Database.js
84 lines (77 loc) · 2.21 KB
/
Database.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
import { ActivityIndicator, Alert, NativeModules } from 'react-native'
import React, { PureComponent } from 'react'
import { Flex, Header, Menu, Screen, Text } from '../../../Library'
import { colors } from '../../../../constants'
import withRelayContext from '../../../../helpers/withRelayContext'
import { RelayContext } from '../../../../relay'
const { CoreModule } = NativeModules
class Database extends PureComponent {
static contextType = RelayContext
static navigationOptions = ({ navigation }) => ({
header: () =>
navigation.getParam('dropDatabase') || (
<Header
navigation={navigation}
title='Database'
titleIcon='database'
backBtn
/>
),
})
generateFakeData = async () => {
try {
await this.props.context.mutations.generateFakeData({
t: true,
})
} catch (err) {
this.setState({ err })
console.error(err)
}
}
dropDatabase = async () => {
this.props.navigation.setParams({ dropDatabase: true })
try {
await CoreModule.dropDatabase()
} catch (err) {
Alert.alert('An error occured, please, kill and restart the app')
console.error(err)
}
this.props.navigation.setParams({
dropDatabase: false,
})
}
render () {
const dropDatabase = this.props.navigation.getParam('dropDatabase')
if (dropDatabase === true) {
return (
<Screen style={{ backgroundColor: colors.white }}>
<Flex.Rows align='center'>
<Flex.Cols align='end'>
<ActivityIndicator size='large' />
</Flex.Cols>
<Text center margin align='start'>
Dropping database, waiting for daemon to restart ...
</Text>
</Flex.Rows>
</Screen>
)
}
return (
<Menu>
<Menu.Section customMarginTop={1}>
<Menu.Item
icon='database'
title='Generate fake data'
onPress={this.generateFakeData}
/>
<Menu.Item
icon='refresh-ccw'
title='Drop database'
onPress={this.dropDatabase}
/>
</Menu.Section>
</Menu>
)
}
}
export default withRelayContext(Database)