-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.js
86 lines (80 loc) · 1.88 KB
/
Main.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
import React from 'react';
import { StyleSheet, View, Text } from 'react-native';
import Form from './Form';
import FetchCasing from './FetchCasing';
import { sizes, weights, grades } from './data';
import calculate from './calculate';
import MyList from './MyList';
export default class Main extends React.Component {
state = {
size: 4.5,
weight: 9.5,
grade: 110000,
length: 1,
optionsData: [],
currName: '',
};
handleListItemPressed = (item) => {
if (this.state.currName === 'size') {
this.setState({
[this.state.currName]: item,
weight: weights[item][0],
optionsData: [],
currName: '',
});
} else {
this.setState({
[this.state.currName]: item,
optionsData: [],
currName: '',
});
}
};
handleSelect = (i) => {
if (this.state.currName !== '') {
this.setState({
optionsData: [],
currName: '',
});
} else if (i === 1) {
this.setState({
optionsData: sizes,
currName: 'size',
});
} else if (i === 2) {
this.setState({
optionsData: weights[this.state.size],
currName: 'weight',
});
} else if (i === 3) {
this.setState({
optionsData: grades,
currName: 'grade',
});
}
};
onChangeText = (length) => {
this.setState({
length,
});
};
render() {
const {
size, weight, grade, length,
} = this.state;
return (
<Form
{...this.state}
onSelect={this.handleSelect}
onListItemPressed={this.handleListItemPressed}
onChangeText={this.onChangeText}
>
<FetchCasing size={size} weight={weight}>
{({ nominalId, driftId }) => (
<MyList items={calculate(size, weight, grade, nominalId, driftId, length)} />
)}
</FetchCasing>
</Form>
);
}
}