Skip to content

Commit 2b6e54b

Browse files
author
woi
committed
refactoring
1 parent 0421095 commit 2b6e54b

File tree

2 files changed

+38
-15
lines changed

2 files changed

+38
-15
lines changed

App/Containers/Example/ExampleScreen.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,28 @@ class ExampleScreen extends React.Component {
2424
}
2525

2626
render() {
27-
let user = this.props.userIsLoading ? '...' : this.props.user
28-
if (user === null) {
29-
user = '??'
27+
let isLoading = this.props.userIsLoading ? 'Data are loading...' : ''
28+
let user = this.props.user
29+
let error = this.props.userErrorMessage
30+
let result = null
31+
if (user && !error) {
32+
result =
33+
"I'm a fake user, my name is " + user.name + '.\n' + this.props.liveInEurope
34+
? 'I live in Europe !'
35+
: "I don't live in Europe."
3036
}
3137

3238
return (
3339
<View style={Style.container}>
3440
<Text style={Style.title}>TheCodingMachine boilerplate</Text>
3541
<Text style={Style.text}>To get started, edit App.js</Text>
36-
<Text style={Style.text}>{instructions}</Text>
37-
<Text style={Style.text}>
38-
{user === '...'
39-
? 'Data are loading...'
40-
: this.props.userErrorMessage
41-
? this.props.userErrorMessage
42-
: ''}
43-
</Text>
44-
<Text style={Style.text}>{user ? "I'm a fake user, my name is " + user.name : ''}.</Text>
45-
<Text style={Style.text}>
46-
{this.props.liveInEurope ? 'I live in Europe !' : "I don't live in Europe."}
47-
</Text>
42+
<Text style={Style.instructions}>{instructions}</Text>
43+
<Text style={Style.loading}>{isLoading}</Text>
44+
{user && !error ? (
45+
<Text style={Style.result}>{result}</Text>
46+
) : (
47+
<Text style={Style.error}>{error}</Text>
48+
)}
4849
<Button onPress={this.props.fetchUser} title="Refresh" />
4950
</View>
5051
)

App/Containers/Example/ExampleScreenStyle.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,26 @@ export default StyleSheet.create({
1919
textAlign: 'center',
2020
marginBottom: 5,
2121
},
22+
instructions: {
23+
...Fonts.style.normal,
24+
textAlign: 'center',
25+
marginBottom: 5,
26+
fontStyle: 'italic',
27+
},
28+
loading: {
29+
...Fonts.style.normal,
30+
textAlign: 'center',
31+
marginBottom: 5,
32+
},
33+
result: {
34+
...Fonts.style.normal,
35+
textAlign: 'center',
36+
marginBottom: 5,
37+
},
38+
error: {
39+
...Fonts.style.normal,
40+
textAlign: 'center',
41+
marginBottom: 5,
42+
color: 'red',
43+
},
2244
})

0 commit comments

Comments
 (0)