From ec6c2ed69a040485a9e70ac514432d655f2eed9e Mon Sep 17 00:00:00 2001 From: Fang Date: Wed, 18 Mar 2020 22:02:37 +0100 Subject: [PATCH] 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. --- .../src/js/components/lib/invite-element.js | 1 + .../src/js/components/lib/invite-search.js | 60 +++++++++++-------- pkg/interface/chat/src/js/components/new.js | 1 + 3 files changed, 38 insertions(+), 24 deletions(-) diff --git a/pkg/interface/chat/src/js/components/lib/invite-element.js b/pkg/interface/chat/src/js/components/lib/invite-element.js index dc15fbc79..278156b0e 100644 --- a/pkg/interface/chat/src/js/components/lib/invite-element.js +++ b/pkg/interface/chat/src/js/components/lib/invite-element.js @@ -65,6 +65,7 @@ export class InviteElement extends Component { groups={{}} contacts={props.contacts} groupResults={false} + shipResults={true} invites={{ groups: [], ships: this.state.members diff --git a/pkg/interface/chat/src/js/components/lib/invite-search.js b/pkg/interface/chat/src/js/components/lib/invite-search.js index f33e74b1b..0c2cf63f6 100644 --- a/pkg/interface/chat/src/js/components/lib/invite-search.js +++ b/pkg/interface/chat/src/js/components/lib/invite-search.js @@ -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 =
; let searchResults =
; + 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 = ; 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} diff --git a/pkg/interface/chat/src/js/components/new.js b/pkg/interface/chat/src/js/components/new.js index 610cb5b7d..d64b3d263 100644 --- a/pkg/interface/chat/src/js/components/new.js +++ b/pkg/interface/chat/src/js/components/new.js @@ -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