chat fe: invite search with/out ships

This lets you specify whether or not you want to include ships in search
results for the InviteSearch component, as is already possible for
groups. This enables group-only searching, as will be used by the next
commit.

Also modifies the placeholder text based on what is included in the
search results.
This commit is contained in:
Fang 2020-03-18 22:02:37 +01:00
parent 54eece11af
commit ec6c2ed69a
No known key found for this signature in database
GPG Key ID: EB035760C1BBA972
3 changed files with 38 additions and 24 deletions

View File

@ -65,6 +65,7 @@ export class InviteElement extends Component {
groups={{}}
contacts={props.contacts}
groupResults={false}
shipResults={true}
invites={{
groups: [],
ships: this.state.members

View File

@ -96,37 +96,37 @@ export class InviteSearch extends Component {
});
}
let shipMatches = this.state.peers.filter(e => {
return e.includes(searchTerm) && !this.props.invites.ships.includes(e);
});
for (let contact of this.state.contacts.keys()) {
let thisContact = this.state.contacts.get(contact);
let match = thisContact.filter(e => {
return e.toLowerCase().includes(searchTerm);
let shipMatches = [];
if (this.props.shipResults) {
shipMatches = this.state.peers.filter(e => {
return e.includes(searchTerm) && !this.props.invites.ships.includes(e);
});
if (match.length > 0) {
if (!(contact in shipMatches)) {
shipMatches.push(contact);
for (let contact of this.state.contacts.keys()) {
let thisContact = this.state.contacts.get(contact);
let match = thisContact.filter(e => {
return e.toLowerCase().includes(searchTerm);
});
if (match.length > 0) {
if (!(contact in shipMatches)) {
shipMatches.push(contact);
}
}
}
let isValid = true;
if (!urbitOb.isValidPatp("~" + searchTerm)) {
isValid = false;
}
if (shipMatches.length === 0 && isValid) {
shipMatches.push(searchTerm);
}
}
this.setState({
searchResults: { groups: groupMatches, ships: shipMatches }
});
let isValid = true;
if (!urbitOb.isValidPatp("~" + searchTerm)) {
isValid = false;
}
if (shipMatches.length === 0 && isValid) {
shipMatches.push(searchTerm);
this.setState({
searchResults: { groups: groupMatches, ships: shipMatches }
});
}
}
}
@ -203,6 +203,18 @@ export class InviteSearch extends Component {
let participants = <div />;
let searchResults = <div />;
let placeholder = '';
if (props.shipResults) {
placeholder = 'ships';
}
if (props.groupResults) {
if (placeholder.length > 0) {
placeholder = placeholder + ' or ';
}
placeholder = placeholder + 'existing groups';
}
placeholder = 'Search for ' + placeholder;
let invErrElem = <span />;
if (state.inviteError) {
invErrElem = (
@ -357,7 +369,7 @@ export class InviteSearch extends Component {
"f7 ba b--gray3 b--gray2-d bg-gray0-d white-d pa3 w-100" +
" db focus-b--black focus-b--white-d"
}
placeholder="Search for ships or existing groups"
placeholder={placeholder}
disabled={searchDisabled}
rows={1}
spellCheck={false}

View File

@ -263,6 +263,7 @@ export class NewScreen extends Component {
contacts={props.contacts}
associations={props.associations}
groupResults={true}
shipResults={true}
invites={{
groups: state.groups,
ships: state.ships