-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistory.js
85 lines (76 loc) · 1.79 KB
/
history.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 React, { Component } from 'react';
import {
ActivityIndicator,
AsyncStorage,
Button,
FlatList,
Text,
View,
} from 'react-native';
export class History extends Component {
static navigationOptions = {
title: 'History'
}
constructor(props) {
super(props)
this.state = {}
this._loadEntries()
}
render() {
const { navigate } = this.props.navigation
return(
<View>
<Button
title='Enter log entry'
onPress={() => navigate('LogEntry')}
/>
<FlatList
data={this.state.data}
extraData={this.state}
renderItem={(entry) => this._renderItem(entry)}
ListHeaderComponent={this._renderHeader}
keyExtractor={this._keyExtractor}
/>
</View>
)
}
async _loadEntries() {
try {
let keys = await AsyncStorage.getAllKeys()
let stores = await AsyncStorage.multiGet(keys)
let lines = stores.map((result, i, store) => {
return store[i][1]
})
this.setState({data: lines})
} catch(error) {
console.error(error)
}
}
_keyExtractor(item, index) {
return item.split(',')[3]
}
_renderHeader() {
return(
<View style={{flex: 4, flexDirection: 'row', justifyContent: 'space-between'}}>
<Text>Date</Text>
<Text>Volume</Text>
<Text>Price</Text>
<Text>Odometer</Text>
</View>
)
}
_renderItem(entry) {
if (entry === null) {
return(<ActivityIndicator />)
}
let [date, volume, price, odometer, isFilled] = entry.item.split(',')
return(
<View style={{flex: 4, flexDirection: 'row', justifyContent: 'space-between'}}>
<Text>{date}</Text>
<Text>{volume}</Text>
<Text>{price}</Text>
<Text>{odometer}</Text>
</View>
)
}
}