Skip to content

Commit 23f87c0

Browse files
committed
centralize the org nicening process
1 parent c6a9895 commit 23f87c0

File tree

3 files changed

+102
-81
lines changed

3 files changed

+102
-81
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// @flow
2+
import type {StudentOrgType} from './types'
3+
4+
export default function cleanOrg(org: StudentOrgType): StudentOrgType {
5+
const name = org.name.trim()
6+
7+
const advisors = org.advisors
8+
.map(c => ({
9+
...c,
10+
name: c.name.trim(),
11+
}))
12+
.filter(c => c.name.length)
13+
14+
const contacts = org.contacts.map(c => ({
15+
...c,
16+
title: c.title.trim(),
17+
firstName: c.firstName.trim(),
18+
lastName: c.lastName.trim(),
19+
}))
20+
21+
const category = org.category.trim()
22+
const meetings = org.meetings.trim()
23+
const description = org.description.trim()
24+
let website = org.website.trim()
25+
website = /^https?:\/\//.test(website) ? website : `http://${website}`
26+
27+
return {
28+
...org,
29+
name,
30+
advisors,
31+
contacts,
32+
category,
33+
meetings,
34+
description,
35+
website,
36+
}
37+
}

source/views/student-orgs/detail.android.js

Lines changed: 35 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @flow
22
import React from 'react'
3-
import {ScrollView, Text, StyleSheet, Linking} from 'react-native'
3+
import {ScrollView, Text, StyleSheet} from 'react-native'
44
import moment from 'moment'
55
import {HtmlView} from '../components/html-view'
66
import {Cell} from 'react-native-tableview-simple'
@@ -10,6 +10,7 @@ import type {StudentOrgType} from './types'
1010
import type {TopLevelViewPropsType} from '../types'
1111
import Communications from 'react-native-communications'
1212
import openUrl from '../components/open-url'
13+
import cleanOrg from './clean-org'
1314

1415
const styles = StyleSheet.create({
1516
name: {
@@ -65,67 +66,56 @@ export class StudentOrgsDetailView extends React.Component {
6566
}
6667

6768
render() {
68-
const data = this.props.org
69-
const name = data.name.trim()
70-
let {
69+
const {
70+
name: orgName,
7171
category,
7272
meetings,
73+
website,
7374
contacts,
74-
description,
7575
advisors,
76-
lastUpdated,
77-
website,
78-
} = data
79-
80-
advisors = advisors.filter(c => c.name.trim().length)
76+
description,
77+
lastUpdated: orgLastUpdated,
78+
} = cleanOrg(this.props.org)
8179

8280
return (
8381
<ScrollView>
84-
<Text style={styles.name}>{name}</Text>
82+
<Text style={styles.name}>{orgName}</Text>
8583

86-
{category.trim()
84+
{category
8785
? <Card header="Category" style={styles.card}>
8886
<Text style={styles.cardBody}>{category}</Text>
8987
</Card>
9088
: null}
9189

92-
{meetings.trim()
90+
{meetings
9391
? <Card header="Meetings" style={styles.card}>
94-
<Cell cellStyle="Basic" title={meetings.trim()} />
92+
<Cell cellStyle="Basic" title={meetings} />
9593
</Card>
9694
: null}
9795

98-
{website.trim()
96+
{website
9997
? <Card header="Website" style={styles.card}>
100-
<Text
101-
onPress={() =>
102-
openUrl(
103-
/^https?:\/\//.test(website.trim())
104-
? website
105-
: `http://${website.trim()}`,
106-
)}
107-
style={styles.cardBody}
108-
>
109-
{/^https?:\/\//.test(website.trim())
110-
? website.trim()
111-
: `http://${website.trim()}`}
98+
<Text onPress={() => openUrl(website)} style={styles.cardBody}>
99+
{website}
112100
</Text>
113101
</Card>
114102
: null}
115103

116-
<Card header="Contact" style={styles.card}>
117-
{contacts.map((c, i) => (
118-
<Text
119-
key={i}
120-
selectable={true}
121-
style={styles.cardBody}
122-
onPress={() => this.openEmail(c.email.trim(), name)}
123-
>
124-
{c.title.trim() ? c.title.trim() + ': ' : ''}
125-
{c.firstName.trim()} {c.lastName.trim()} ({c.email.trim()})
126-
</Text>
127-
))}
128-
</Card>
104+
{contacts.length
105+
? <Card header="Contact" style={styles.card}>
106+
{contacts.map((c, i) => (
107+
<Text
108+
key={i}
109+
selectable={true}
110+
style={styles.cardBody}
111+
onPress={() => this.openEmail(c.email, orgName)}
112+
>
113+
{c.title ? c.title + ': ' : ''}
114+
{c.firstName} {c.lastName} ({c.email})
115+
</Text>
116+
))}
117+
</Card>
118+
: null}
129119

130120
{advisors.length
131121
? <Card
@@ -137,18 +127,17 @@ export class StudentOrgsDetailView extends React.Component {
137127
key={i}
138128
selectable={true}
139129
style={styles.cardBody}
140-
onPress={() => this.openEmail(c.email.trim(), name)}
130+
onPress={() => this.openEmail(c.email, orgName)}
141131
>
142-
{c.name.trim()} ({c.email.trim()})
132+
{c.name} ({c.email})
143133
</Text>
144134
))}
145135
</Card>
146136
: null}
147137

148-
{description.trim()
138+
{description
149139
? <Card header="Description" style={styles.card}>
150140
<HtmlView
151-
scrollEnabled={true}
152141
style={styles.description}
153142
html={`
154143
<style>
@@ -160,7 +149,7 @@ export class StudentOrgsDetailView extends React.Component {
160149
max-width: 100%;
161150
}
162151
</style>
163-
${description.trim()}
152+
${description}
164153
`}
165154
/>
166155
</Card>
@@ -169,7 +158,7 @@ export class StudentOrgsDetailView extends React.Component {
169158
<Text selectable={true} style={[styles.footer, styles.lastUpdated]}>
170159
Last updated:
171160
{' '}
172-
{moment(lastUpdated, 'MMMM, DD YYYY HH:mm:ss').calendar()}
161+
{moment(orgLastUpdated, 'MMMM, DD YYYY HH:mm:ss').calendar()}
173162
</Text>
174163

175164
<Text selectable={true} style={[styles.footer, styles.poweredBy]}>

source/views/student-orgs/detail.ios.js

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as c from '../components/colors'
88
import type {StudentOrgType} from './types'
99
import type {TopLevelViewPropsType} from '../types'
1010
import openUrl from '../components/open-url'
11+
import cleanOrg from './clean-org'
1112

1213
const styles = StyleSheet.create({
1314
name: {
@@ -51,32 +52,29 @@ export class StudentOrgsDetailView extends React.Component {
5152
}
5253

5354
render() {
54-
const data = this.props.org
55-
const name = data.name.trim()
56-
let {
55+
const {
56+
name: orgName,
5757
category,
5858
meetings,
59+
website,
5960
contacts,
60-
description,
6161
advisors,
62-
lastUpdated,
63-
website,
64-
} = data
65-
66-
advisors = advisors.filter(c => c.name.trim().length)
62+
description,
63+
lastUpdated: orgLastUpdated,
64+
} = cleanOrg(this.props.org)
6765

6866
return (
6967
<ScrollView>
7068
<TableView>
71-
<Text selectable={true} style={styles.name}>{name}</Text>
69+
<Text selectable={true} style={styles.name}>{orgName}</Text>
7270

73-
{category.trim()
71+
{category
7472
? <Section header="CATEGORY">
7573
<Cell cellStyle="Basic" title={category} />
7674
</Section>
7775
: null}
7876

79-
{meetings.trim()
77+
{meetings
8078
? <Section header="MEETINGS">
8179
<Cell
8280
cellContentView={
@@ -87,34 +85,31 @@ export class StudentOrgsDetailView extends React.Component {
8785
</Section>
8886
: null}
8987

90-
{website.trim()
88+
{website
9189
? <Section header="WEBSITE">
9290
<Cell
9391
cellStyle="Basic"
9492
accessory="DisclosureIndicator"
9593
title={website}
96-
onPress={() =>
97-
openUrl(
98-
/^https?:\/\//.test(website)
99-
? website
100-
: `http://${website}`,
101-
)}
94+
onPress={() => openUrl(website)}
10295
/>
10396
</Section>
10497
: null}
10598

106-
<Section header="CONTACT">
107-
{contacts.map((c, i) => (
108-
<Cell
109-
key={i}
110-
cellStyle={c.title ? 'Subtitle' : 'Basic'}
111-
accessory="DisclosureIndicator"
112-
title={`${c.firstName.trim()} ${c.lastName.trim()}`}
113-
detail={c.title.trim()}
114-
onPress={() => Linking.openURL(`mailto:${c.email}`)}
115-
/>
116-
))}
117-
</Section>
99+
{contacts.length
100+
? <Section header="CONTACT">
101+
{contacts.map((c, i) => (
102+
<Cell
103+
key={i}
104+
cellStyle={c.title ? 'Subtitle' : 'Basic'}
105+
accessory="DisclosureIndicator"
106+
title={`${c.firstName} ${c.lastName}`}
107+
detail={c.title}
108+
onPress={() => Linking.openURL(`mailto:${c.email}`)}
109+
/>
110+
))}
111+
</Section>
112+
: null}
118113

119114
{advisors.length
120115
? <Section header={advisors.length === 1 ? 'ADVISOR' : 'ADVISORS'}>
@@ -123,14 +118,14 @@ export class StudentOrgsDetailView extends React.Component {
123118
key={i}
124119
cellStyle="Basic"
125120
accessory="DisclosureIndicator"
126-
title={c.name.trim()}
121+
title={c.name}
127122
onPress={() => Linking.openURL(`mailto:${c.email}`)}
128123
/>
129124
))}
130125
</Section>
131126
: null}
132127

133-
{description.trim()
128+
{description
134129
? <Section header="DESCRIPTION">
135130
<HtmlView
136131
style={styles.description}
@@ -144,7 +139,7 @@ export class StudentOrgsDetailView extends React.Component {
144139
max-width: 100%;
145140
}
146141
</style>
147-
${description.trim()}
142+
${description}
148143
`}
149144
/>
150145
</Section>
@@ -153,7 +148,7 @@ export class StudentOrgsDetailView extends React.Component {
153148
<Text selectable={true} style={[styles.footer, styles.lastUpdated]}>
154149
Last updated:
155150
{' '}
156-
{moment(lastUpdated, 'MMMM, DD YYYY HH:mm:ss').calendar()}
151+
{moment(orgLastUpdated, 'MMMM, DD YYYY HH:mm:ss').calendar()}
157152
</Text>
158153

159154
<Text selectable={true} style={[styles.footer, styles.poweredBy]}>

0 commit comments

Comments
 (0)