invite-search: handle suggestions for short searches

Triggers invitee suggestions after one character of input. To
compensate for the potential explosion of suggestions, we
tighten our group searching criteria and truncate the
ship suggestions on short searches. Also addresses a bug where names of
groups were not being downcased before search.

Fixes #2635
This commit is contained in:
Liam Fitzgerald 2020-04-09 09:43:24 +10:00
parent eef6e56dca
commit e7887b34c3
4 changed files with 46 additions and 12 deletions

View File

@ -88,11 +88,11 @@ export class InviteSearch extends Component {
this.setState({ searchValue: event.target.value });
if (searchTerm.length < 2) {
if (searchTerm.length < 1) {
this.setState({ searchResults: { groups: [], ships: [] } });
}
if (searchTerm.length > 2) {
if (searchTerm.length > 0) {
if (this.state.inviteError === true) {
this.setState({ inviteError: false });
}
@ -100,7 +100,7 @@ export class InviteSearch extends Component {
let groupMatches = [];
if (this.props.groupResults) {
groupMatches = this.state.groups.filter(e => {
return (e[0].includes(searchTerm) || e[1].includes(searchTerm));
return (e[0].includes(searchTerm) || e[1].toLowerCase().includes(searchTerm));
});
}
@ -141,6 +141,15 @@ export class InviteSearch extends Component {
this.setState({ selected: newSelection })
}
if(searchTerm.length < 3) {
groupMatches = groupMatches.filter(([, name]) =>
name.toLowerCase().split(' ').some(s => s.startsWith(searchTerm))
).sort((a,b) => a[1].length - b[1].length);
shipMatches = shipMatches.slice(0,3);
}
this.setState({
searchResults: { groups: groupMatches, ships: shipMatches }
});

View File

@ -89,11 +89,11 @@ export class InviteSearch extends Component {
this.setState({ searchValue: event.target.value });
if (searchTerm.length < 2) {
if (searchTerm.length < 1) {
this.setState({ searchResults: { groups: [], ships: [] } });
}
if (searchTerm.length > 2) {
if (searchTerm.length > 0) {
if (this.state.inviteError === true) {
this.setState({ inviteError: false });
}
@ -101,7 +101,7 @@ export class InviteSearch extends Component {
let groupMatches = [];
if (this.props.groupResults) {
groupMatches = this.state.groups.filter(e => {
return e[0].includes(searchTerm) || e[1].includes(searchTerm);
return e[0].includes(searchTerm) || e[1].toLowerCase().includes(searchTerm);
});
}
@ -142,6 +142,15 @@ export class InviteSearch extends Component {
this.setState({ selected: newSelection })
}
if(searchTerm.length < 3) {
groupMatches = groupMatches.filter(([, name]) =>
name.toLowerCase().split(' ').some(s => s.startsWith(searchTerm))
).sort((a,b) => a[1].length - b[1].length);
shipMatches = shipMatches.slice(0,3);
}
this.setState({
searchResults: { groups: groupMatches, ships: shipMatches }
});

View File

@ -89,11 +89,11 @@ export class InviteSearch extends Component {
this.setState({ searchValue: event.target.value });
if (searchTerm.length < 2) {
if (searchTerm.length < 1) {
this.setState({ searchResults: { groups: [], ships: [] } });
}
if (searchTerm.length > 2) {
if (searchTerm.length > 0) {
if (this.state.inviteError === true) {
this.setState({ inviteError: false });
}
@ -101,7 +101,7 @@ export class InviteSearch extends Component {
let groupMatches = [];
if (this.props.groupResults) {
groupMatches = this.state.groups.filter(e => {
return e[0].includes(searchTerm) || e[1].includes(searchTerm);
return e[0].includes(searchTerm) || e[1].toLowerCase().includes(searchTerm);
});
}
@ -142,6 +142,14 @@ export class InviteSearch extends Component {
this.setState({ selected: newSelection })
}
if(searchTerm.length < 3) {
groupMatches = groupMatches.filter(([, name]) =>
name.toLowerCase().split(' ').some(s => s.startsWith(searchTerm))
).sort((a,b) => a[1].length - b[1].length);
shipMatches = shipMatches.slice(0,3);
}
this.setState({
searchResults: { groups: groupMatches, ships: shipMatches }
});

View File

@ -89,11 +89,11 @@ export class InviteSearch extends Component {
this.setState({ searchValue: event.target.value });
if (searchTerm.length < 2) {
if (searchTerm.length < 1) {
this.setState({ searchResults: { groups: [], ships: [] } });
}
if (searchTerm.length > 2) {
if (searchTerm.length > 0) {
if (this.state.inviteError === true) {
this.setState({ inviteError: false });
}
@ -101,7 +101,7 @@ export class InviteSearch extends Component {
let groupMatches = [];
if (this.props.groupResults) {
groupMatches = this.state.groups.filter(e => {
return e[0].includes(searchTerm) || e[1].includes(searchTerm);
return e[0].includes(searchTerm) || e[1].toLowerCase().includes(searchTerm);
});
}
@ -142,6 +142,14 @@ export class InviteSearch extends Component {
this.setState({ selected: newSelection })
}
if(searchTerm.length < 3) {
groupMatches = groupMatches.filter(([, name]) =>
name.toLowerCase().split(' ').some(s => s.startsWith(searchTerm))
).sort((a,b) => a[1].length - b[1].length);
shipMatches = shipMatches.slice(0,3);
}
this.setState({
searchResults: { groups: groupMatches, ships: shipMatches }
});