Limit search input to first character matching when only one character is typed

pull/3090/head
Mark McDowall 5 years ago
parent 2ee0ae1f9e
commit 5293349785

@ -154,8 +154,33 @@ class SeriesSearchInput extends Component {
}
onSuggestionsFetchRequested = ({ value }) => {
const fuse = new Fuse(this.props.series, fuseOptions);
const suggestions = fuse.search(value);
const { series } = this.props;
let suggestions = [];
if (value.length === 1) {
suggestions = series.reduce((acc, s) => {
if (s.firstCharacter === value.toLowerCase()) {
acc.push({
item: s,
indices: [
[0, 0]
],
matches: [
{
value: s.title,
key: 'title'
}
],
arrayIndex: 0
});
}
return acc;
}, []);
} else {
const fuse = new Fuse(series, fuseOptions);
suggestions = fuse.search(value);
}
this.setState({ suggestions });
}

@ -26,6 +26,7 @@ function createCleanSeriesSelector() {
sortTitle,
images,
alternateTitles,
firstCharacter: title.charAt(0).toLowerCase(),
tags: tags.map((id) => {
return allTags.find((tag) => tag.id === id);
})

Loading…
Cancel
Save