Skip to content

Commit 1bcbbe6

Browse files
authored
Merge pull request #2065 from StoDevX/center-wifi-text
WiFi Issue Reporting Screen Improvements
2 parents b547a28 + 743a2cf commit 1bcbbe6

File tree

1 file changed

+52
-14
lines changed

1 file changed

+52
-14
lines changed

source/views/help/wifi.js

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import * as React from 'react'
44
import {StyleSheet} from 'react-native'
55
import glamorous from 'glamorous-native'
6+
import * as c from '../components/colors'
67
import {Card} from '../components/card'
78
import {Button} from '../components/button'
89
import deviceInfo from 'react-native-device-info'
@@ -51,38 +52,54 @@ function reportToServer(data) {
5152
return fetch(url, {method: 'POST', body: JSON.stringify(data)})
5253
}
5354

55+
const messages = {
56+
init: 'Report',
57+
collecting: 'Collecting data…',
58+
reporting: 'Reporting data…',
59+
done: 'Thanks!',
60+
error: 'Try again?',
61+
}
62+
5463
type Props = {}
5564

5665
type State = {
57-
status: string,
66+
error: ?string,
67+
status: $Keys<typeof messages>,
5868
}
5969

6070
export class ReportWifiProblemView extends React.Component<Props, State> {
6171
state = {
62-
status: '',
72+
error: null,
73+
status: 'init',
6374
}
6475

6576
start = async () => {
66-
this.setState(() => ({status: 'Collecting data…'}))
77+
this.setState(() => ({status: 'collecting', error: ''}))
6778
const [position, device] = await Promise.all([getPosition(), collectData()])
68-
this.setState(() => ({status: 'Reporting data…'}))
79+
this.setState(() => ({status: 'reporting'}))
6980
try {
7081
let data = {position, device, version: 1}
7182
await retry(() => reportToServer(data), {retries: 10})
7283
await delay(1000)
73-
this.setState(() => ({status: 'Thanks!'}))
84+
this.setState(() => ({status: 'done'}))
7485
} catch (err) {
7586
reportNetworkProblem(err)
7687
this.setState(() => ({
77-
status: 'Apologies; there was an error. Please try again later.',
88+
error: 'Apologies; there was an error. Please try again later.',
89+
status: 'error',
7890
}))
7991
}
8092
}
8193

8294
render() {
95+
const buttonMessage = messages[this.state.status] || 'Error'
96+
const buttonEnabled =
97+
this.state.status === 'init' || this.state.status === 'error'
98+
8399
return (
84100
<Card style={styles.card}>
85101
<Title selectable={true}>Report a Wi-Fi Problem</Title>
102+
86103
<Description selectable={true}>
87104
If you are having an issue connecting to any of the St. Olaf College
88105
Wi-Fi networks, please tap the button below.
@@ -92,14 +109,21 @@ export class ReportWifiProblemView extends React.Component<Props, State> {
92109
will record your current location and some general information about
93110
the device you are using, then send it to a server that IT maintains.
94111
</Description>
95-
<Description selectable={true}>
112+
<Description selectable={true} style={styles.lastParagraph}>
96113
The networking team can then use this information to identify where
97114
people are having issues!
98115
</Description>
116+
117+
{this.state.error ? (
118+
<Error>
119+
<ErrorMessage selectable={true}>{this.state.error}</ErrorMessage>
120+
</Error>
121+
) : null}
122+
99123
<Button
100-
disabled={this.state.status !== ''}
124+
disabled={!buttonEnabled}
101125
onPress={this.start}
102-
title={this.state.status || 'Report'}
126+
title={buttonMessage}
103127
/>
104128
</Card>
105129
)
@@ -109,19 +133,33 @@ export class ReportWifiProblemView extends React.Component<Props, State> {
109133
const Title = glamorous.text({
110134
fontWeight: '700',
111135
fontSize: 16,
112-
marginVertical: 15,
136+
marginBottom: 10,
137+
textAlign: 'center',
113138
})
114139

115140
const Description = glamorous.text({
116141
fontSize: 14,
117-
marginBottom: 15,
118-
justifyContent: 'space-between',
119-
alignItems: 'center',
142+
marginBottom: 10,
143+
})
144+
145+
const Error = glamorous.view({
146+
backgroundColor: c.warning,
147+
padding: 10,
148+
borderRadius: 5,
149+
marginTop: 10,
150+
marginBottom: 0,
151+
})
152+
153+
const ErrorMessage = glamorous.text({
154+
fontSize: 14,
120155
})
121156

122157
const styles = StyleSheet.create({
123158
card: {
124159
paddingHorizontal: 20,
125-
paddingVertical: 5,
160+
paddingVertical: 15,
161+
},
162+
lastParagraph: {
163+
marginBottom: 0,
126164
},
127165
})

0 commit comments

Comments
 (0)