Skip to content

Commit 08f1a45

Browse files
committed
apply the fix to Student Orgs too
1 parent 04e7a1e commit 08f1a45

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

source/views/student-orgs/list.js

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@ import {
1717
} from '../components/list'
1818
import {trackOrgOpen} from '../../analytics'
1919
import {reportNetworkProblem} from '../../lib/report-network-problem'
20-
import size from 'lodash/size'
2120
import sortBy from 'lodash/sortBy'
2221
import groupBy from 'lodash/groupBy'
2322
import uniq from 'lodash/uniq'
2423
import words from 'lodash/words'
2524
import deburr from 'lodash/deburr'
26-
import filter from 'lodash/filter'
2725
import startCase from 'lodash/startCase'
2826
import * as c from '../components/colors'
2927
import type {StudentOrgType} from './types'
@@ -70,7 +68,7 @@ type Props = TopLevelViewPropsType
7068

7169
type State = {
7270
orgs: Array<StudentOrgType>,
73-
results: {[key: string]: StudentOrgType[]},
71+
query: string,
7472
refreshing: boolean,
7573
error: boolean,
7674
loading: boolean,
@@ -86,7 +84,7 @@ export class StudentOrgsView extends React.PureComponent<Props, State> {
8684

8785
state = {
8886
orgs: [],
89-
results: {},
87+
query: '',
9088
refreshing: false,
9189
loading: true,
9290
error: false,
@@ -119,8 +117,7 @@ export class StudentOrgsView extends React.PureComponent<Props, State> {
119117
})
120118

121119
const sorted = sortBy(withSortableNames, '$sortableName')
122-
const grouped = groupBy(sorted, '$groupableName')
123-
this.setState(() => ({orgs: sorted, results: grouped}))
120+
this.setState(() => ({orgs: sorted}))
124121
}
125122

126123
refresh = async () => {
@@ -178,28 +175,15 @@ export class StudentOrgsView extends React.PureComponent<Props, State> {
178175
}
179176

180177
performSearch = (text: ?string) => {
181-
if (!text) {
182-
this.setState(state => ({
183-
results: groupBy(state.orgs, '$groupableName'),
184-
}))
185-
return
186-
}
187-
188-
const query = text.toLowerCase()
189-
this.setState(state => {
190-
const filteredResults = filter(state.orgs, org =>
191-
orgToArray(org).some(word => word.startsWith(query)),
192-
)
193-
return {results: groupBy(filteredResults, '$groupableName')}
194-
})
178+
this.setState(() => ({query: text ? text.toLowerCase() : ''}))
195179
}
196180

197181
render() {
198182
if (this.state.loading) {
199183
return <LoadingView />
200184
}
201185

202-
if (!size(this.state.orgs)) {
186+
if (!this.state.orgs.length) {
203187
return <NoticeView text="No organizations found." />
204188
}
205189

@@ -210,14 +194,23 @@ export class StudentOrgsView extends React.PureComponent<Props, State> {
210194
/>
211195
)
212196

197+
let results = this.state.orgs
198+
if (this.state.query) {
199+
let {query, orgs} = this.state
200+
results = orgs.filter(org =>
201+
orgToArray(org).some(word => word.startsWith(query)),
202+
)
203+
}
204+
let groupedResults = groupBy(results, '$groupableName')
205+
213206
return (
214207
<SearchableAlphabetListView
215208
cell={this.renderRow}
216209
cellHeight={
217210
ROW_HEIGHT +
218211
(Platform.OS === 'ios' ? 11 / 12 * StyleSheet.hairlineWidth : 0)
219212
}
220-
data={this.state.results}
213+
data={groupedResults}
221214
onSearch={this.performSearch}
222215
refreshControl={refreshControl}
223216
renderSeparator={this.renderSeparator}

0 commit comments

Comments
 (0)