Skip to content

Commit e42e8c5

Browse files
committed
rework the detail screens with more components
1 parent 674f40f commit e42e8c5

File tree

2 files changed

+78
-114
lines changed

2 files changed

+78
-114
lines changed

source/views/sis/student-work/detail.android.js

Lines changed: 40 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -48,128 +48,110 @@ const styles = StyleSheet.create({
4848
},
4949
})
5050

51-
function renderTitle(title: string, category: string) {
52-
return title || category
51+
function Title({job}: {job: JobType}) {
52+
return job.title || job.type
5353
? <View>
54-
<Text style={styles.name}>{title}</Text>
55-
<Text style={styles.subtitle}>{category}</Text>
54+
<Text style={styles.name}>{job.title}</Text>
55+
<Text style={styles.subtitle}>{job.type}</Text>
5656
</View>
5757
: null
5858
}
5959

60-
function renderContact(
61-
jobTitle: string,
62-
office: string,
63-
contactName: string,
64-
emailAddress: string,
65-
) {
66-
contactName = contactName || email
67-
return office || contactName
60+
function Contact({job}: {job: JobType}) {
61+
const contactName = getContactName(job).trim() || job.contactEmail
62+
return job.office || contactName
6863
? <Card header="Contact" style={styles.card}>
6964
<Text
7065
style={styles.cardBody}
71-
onPress={() => email([emailAddress], null, null, jobTitle, '')}
66+
onPress={() => email([job.contactEmail], null, null, job.title, '')}
7267
>
73-
{contactName} {emailAddress ? `(${emailAddress})` : ''}
68+
{contactName} {job.title ? `(${job.title})` : ''}
7469
{'\n'}
75-
{office}
70+
{job.office}
7671
</Text>
7772
</Card>
7873
: null
7974
}
8075

81-
function renderHours(timeOfHours: number | string, hoursPerWeek: string) {
82-
const ending = hoursPerWeek == 'Full-time' ? '' : ' hrs/week'
83-
return timeOfHours && hoursPerWeek
76+
function Hours({job}: {job: JobType}) {
77+
const ending = job.hoursPerWeek == 'Full-time' ? '' : ' hrs/week'
78+
return job.timeOfHours && job.hoursPerWeek
8479
? <Card header="Hours" style={styles.card}>
8580
<Text style={styles.cardBody}>
86-
{timeOfHours}
81+
{job.timeOfHours}
8782
{'\n'}
88-
{hoursPerWeek + ending}
83+
{job.hoursPerWeek + ending}
8984
</Text>
9085
</Card>
9186
: null
9287
}
9388

94-
function renderDescription(description: string) {
95-
return description
89+
function Description({job}: {job: JobType}) {
90+
return job.description
9691
? <Card header="Description" style={styles.card}>
9792
<Text style={styles.cardBody}>
98-
{description}
93+
{job.description}
9994
</Text>
10095
</Card>
10196
: null
10297
}
10398

104-
function renderSkills(skills: string) {
105-
return skills
99+
function Skills({job}: {job: JobType}) {
100+
return job.skills
106101
? <Card header="Skills" style={styles.card}>
107102
<Text style={styles.cardBody}>
108-
{skills}
103+
{job.skills}
109104
</Text>
110105
</Card>
111106
: null
112107
}
113108

114-
function renderComments(comments: string) {
115-
return comments
109+
function Comments({job}: {job: JobType}) {
110+
return job.comments
116111
? <Card header="Comments" style={styles.card}>
117112
<Text style={styles.cardBody}>
118-
{comments}
113+
{job.comments}
119114
</Text>
120115
</Card>
121116
: null
122117
}
123118

124-
function renderLinks(links: string[]) {
119+
function Links({job}: {job: JobType}) {
120+
const links = getLinksFromJob(job)
125121
return links.length
126122
? <Card header="LINKS" style={styles.card}>
127-
{links.map((url, i) => (
128-
<Text key={i} style={styles.cardBody} onPress={() => openUrl(url)}>
123+
{links.map(url => (
124+
<Text key={url} style={styles.cardBody} onPress={() => openUrl(url)}>
129125
{url}
130126
</Text>
131127
))}
132128
</Card>
133129
: null
134130
}
135131

136-
function renderLastUpdated(lastModified: string) {
137-
return lastModified
132+
function LastUpdated({when}: {when: string}) {
133+
return when
138134
? <Text selectable={true} style={[styles.footer, styles.lastUpdated]}>
139135
Last updated:
140136
{' '}
141-
{moment(lastModified, 'YYYY/MM/DD').calendar()}
137+
{moment(when, 'YYYY/MM/DD').calendar()}
142138
</Text>
143139
: null
144140
}
145141

146142
export default function JobDetailView({job}: {job: JobType}) {
147-
const cleaned = cleanJob(job)
148-
const contactName = getContactName(cleaned)
149-
const links = getLinksFromJob(cleaned)
150-
const {
151-
title,
152-
type,
153-
office,
154-
contactEmail,
155-
timeOfHours,
156-
hoursPerWeek,
157-
description,
158-
skills,
159-
comments,
160-
lastModified,
161-
} = cleaned
143+
job = cleanJob(job)
162144

163145
return (
164146
<ScrollView>
165-
{renderTitle(title, type)}
166-
{renderContact(title, office, contactName, contactEmail)}
167-
{renderHours(timeOfHours, hoursPerWeek)}
168-
{renderDescription(description)}
169-
{renderSkills(skills)}
170-
{renderComments(comments)}
171-
{renderLinks(links)}
172-
{renderLastUpdated(lastModified)}
147+
<Title job={job} />
148+
<Contact job={job} />
149+
<Hours job={job} />
150+
<Description job={job} />
151+
<Skills job={job} />
152+
<Comments job={job} />
153+
<Links job={job} />
154+
<LastUpdated when={job.lastModified} />
173155
</ScrollView>
174156
)
175157
}

source/views/sis/student-work/detail.ios.js

Lines changed: 38 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -23,95 +23,91 @@ const styles = StyleSheet.create({
2323
},
2424
})
2525

26-
function renderTitle(title: string, category: string) {
27-
return title || category
26+
function Title({job}: {job: JobType}) {
27+
return job.title || job.type
2828
? <Section header="JOB">
29-
<Cell cellStyle="Subtitle" title={title} detail={category} />
29+
<Cell cellStyle="Subtitle" title={job.title} detail={job.type} />
3030
</Section>
3131
: null
3232
}
3333

34-
function renderContact(
35-
jobTitle: string,
36-
office: string,
37-
contactName: string,
38-
emailAddress: string,
39-
) {
40-
contactName = contactName || email
41-
return office || contactName
34+
function Contact({job}: {job: JobType}) {
35+
const contactName = getContactName(job).trim() || job.contactEmail
36+
return job.office || contactName
4237
? <Section header="CONTACT">
4338
<Cell
4439
cellStyle="Subtitle"
4540
title={contactName}
46-
detail={office}
41+
detail={job.office}
4742
accessory="DisclosureIndicator"
48-
onPress={() => email([emailAddress], null, null, jobTitle, '')}
43+
onPress={() => email([job.contactEmail], null, null, job.title, '')}
4944
/>
5045
</Section>
5146
: null
5247
}
5348

54-
function renderHours(timeOfHours: number | string, hoursPerWeek: string) {
55-
const ending = hoursPerWeek == 'Full-time' ? '' : ' hrs/week'
56-
return timeOfHours && hoursPerWeek
49+
function Hours({job}: {job: JobType}) {
50+
const ending = job.hoursPerWeek == 'Full-time' ? '' : ' hrs/week'
51+
return job.timeOfHours && job.hoursPerWeek
5752
? <Section header="HOURS">
5853
<Cell
5954
cellStyle="Subtitle"
60-
title={timeOfHours}
61-
detail={hoursPerWeek + ending}
55+
title={job.timeOfHours}
56+
detail={job.hoursPerWeek + ending}
6257
/>
6358
</Section>
6459
: null
6560
}
6661

67-
function renderDescription(description: string) {
68-
return description
62+
function Description({job}: {job: JobType}) {
63+
return job.description
6964
? <Section header="DESCRIPTION">
7065
<Cell
7166
cellContentView={
7267
<Text selectable={true} style={styles.selectable}>
73-
{description}
68+
{job.description}
7469
</Text>
7570
}
7671
/>
7772
</Section>
7873
: null
7974
}
8075

81-
function renderSkills(skills: string) {
82-
return skills
76+
function Skills({job}: {job: JobType}) {
77+
return job.skills
8378
? <Section header="SKILLS">
8479
<Cell
8580
cellContentView={
8681
<Text selectable={true} style={styles.selectable}>
87-
{skills}
82+
{job.skills}
8883
</Text>
8984
}
9085
/>
9186
</Section>
9287
: null
9388
}
9489

95-
function renderComments(comments: string) {
96-
return comments
90+
function Comments({job}: {job: JobType}) {
91+
return job.comments
9792
? <Section header="COMMENTS">
9893
<Cell
9994
cellContentView={
10095
<Text selectable={true} style={styles.selectable}>
101-
{comments}
96+
{job.comments}
10297
</Text>
10398
}
10499
/>
105100
</Section>
106101
: null
107102
}
108103

109-
function renderLinks(links: string[]) {
104+
function Links({job}: {job: JobType}) {
105+
const links = getLinksFromJob(job)
110106
return links.length
111107
? <Section header="LINKS">
112-
{links.map((url, i) => (
108+
{links.map(url => (
113109
<Cell
114-
key={i}
110+
key={url}
115111
cellStyle="Title"
116112
title={url}
117113
accessory="DisclosureIndicator"
@@ -122,45 +118,31 @@ function renderLinks(links: string[]) {
122118
: null
123119
}
124120

125-
function renderLastUpdated(lastModified: string) {
126-
return lastModified
121+
function LastUpdated({when}: {when: string}) {
122+
return when
127123
? <Text selectable={true} style={[styles.footer, styles.lastUpdated]}>
128124
Last updated:
129125
{' '}
130-
{moment(lastModified, 'YYYY/MM/DD').calendar()}
126+
{moment(when, 'YYYY/MM/DD').calendar()}
131127
</Text>
132128
: null
133129
}
134130

135131
export default function JobDetailView({job}: {job: JobType}) {
136-
const cleaned = cleanJob(job)
137-
const contactName = getContactName(cleaned)
138-
const links = getLinksFromJob(cleaned)
139-
const {
140-
title,
141-
type,
142-
office,
143-
contactEmail,
144-
timeOfHours,
145-
hoursPerWeek,
146-
description,
147-
skills,
148-
comments,
149-
lastModified,
150-
} = cleaned
132+
job = cleanJob(job)
151133

152134
return (
153135
<ScrollView>
154136
<TableView>
155-
{renderTitle(title, type)}
156-
{renderContact(title, office, contactName, contactEmail)}
157-
{renderHours(timeOfHours, hoursPerWeek)}
158-
{renderDescription(description)}
159-
{renderSkills(skills)}
160-
{renderComments(comments)}
161-
{renderLinks(links)}
137+
<Title job={job} />
138+
<Contact job={job} />
139+
<Hours job={job} />
140+
<Description job={job} />
141+
<Skills job={job} />
142+
<Comments job={job} />
143+
<Links job={job} />
162144
</TableView>
163-
{renderLastUpdated(lastModified)}
145+
<LastUpdated when={job.lastModified} />
164146
</ScrollView>
165147
)
166148
}

0 commit comments

Comments
 (0)