-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStats.js
78 lines (71 loc) · 2 KB
/
Stats.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
/**
* @file Stats.js
* @author Claire Fleckney
* @date March 27, 2023
* @brief This is the component that gets
* displayed on the stats screen
*/
import React, { Component } from 'react';
import { Text, View } from 'react-native';
import styles from './Style';
export default class Stat extends Component {
constructor(props) {
super(props);
this.state = {
record: null,
}
}
/**
* Sets the record state variable
* @function setRecords()
* @param {Array} record Character Records
*/
setRecords = (record) => {
this.setState({ record: record });
}
componentDidMount() {
this.update();
}
/**
* Pulls records from the db
* @function update()
* @see setRecords()
*/
update = () => {
this.props.db.transaction(
(tx) => {
tx.executeSql(
'select * from player order by id desc limit 15;',
[],
(_, { rows: { _array } }) => this.setRecords(_array),
);
},
)
}
render() {
if (this.state.record === null || this.state.record.length === 0) {
return null;
}
return (
<>
<View style={styles.stats}>
<View>
{this.state.record.map(({ id, name }) => (
<Text key={id} style={styles.statText}>{name}</Text>
))}
</View>
<View>
{this.state.record.map(({ id, job }) => (
<Text key={id} style={styles.statText}>{job}</Text>
))}
</View>
<View>
{this.state.record.map(({ id, victory }) => (
<Text key={id} style={styles.statText}>{victory ? 'Yes' : 'No'}</Text>
))}
</View>
</View>
</>
)
}
}