Skip to content

Commit 04e7a1e

Browse files
committed
initial pass at fixing dictionary
fix flow State for DictionaryList fix trailing spaces
1 parent c3c779f commit 04e7a1e

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

source/views/dictionary/list.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const styles = StyleSheet.create({
4848
type Props = TopLevelViewPropsType
4949

5050
type State = {
51-
results: Array<WordType>,
51+
query: string,
5252
allTerms: Array<WordType>,
5353
refreshing: boolean,
5454
}
@@ -60,7 +60,7 @@ export class DictionaryView extends React.PureComponent<Props, State> {
6060
}
6161

6262
state = {
63-
results: defaultData.data,
63+
query: '',
6464
allTerms: defaultData.data,
6565
refreshing: false,
6666
}
@@ -126,17 +126,7 @@ export class DictionaryView extends React.PureComponent<Props, State> {
126126
)
127127

128128
performSearch = (text: ?string) => {
129-
if (!text) {
130-
this.setState(state => ({results: state.allTerms}))
131-
return
132-
}
133-
134-
const query = text.toLowerCase()
135-
this.setState(state => ({
136-
results: state.allTerms.filter(term =>
137-
termToArray(term).some(word => word.startsWith(query)),
138-
),
139-
}))
129+
this.setState(() => ({query: text ? text.toLowerCase() : ''}))
140130
}
141131

142132
render() {
@@ -147,14 +137,22 @@ export class DictionaryView extends React.PureComponent<Props, State> {
147137
/>
148138
)
149139

140+
let results = this.state.allTerms
141+
if (this.state.query) {
142+
const {query, allTerms} = this.state
143+
results = allTerms.filter(term =>
144+
termToArray(term).some(word => word.startsWith(query)),
145+
)
146+
}
147+
150148
return (
151149
<SearchableAlphabetListView
152150
cell={this.renderRow}
153151
cellHeight={
154152
ROW_HEIGHT +
155153
(Platform.OS === 'ios' ? 11 / 12 * StyleSheet.hairlineWidth : 0)
156154
}
157-
data={groupBy(this.state.results, item => item.word[0])}
155+
data={groupBy(results, item => item.word[0])}
158156
onSearch={this.performSearch}
159157
refreshControl={refreshControl}
160158
renderSeparator={this.renderSeparator}

0 commit comments

Comments
 (0)