diff options
author | hmhealey <harrisonmhealey@gmail.com> | 2015-11-30 16:20:42 -0500 |
---|---|---|
committer | hmhealey <harrisonmhealey@gmail.com> | 2015-12-01 16:27:21 -0500 |
commit | 6d10b103189168c556456319115774b41ee5ac73 (patch) | |
tree | 4df873c45d6fb14942c7bc9ead19bab73696cb07 /web/react/components/search_suggestion_list.jsx | |
parent | e87c89be25065ff4d0d020b98c71e1ddec28ae49 (diff) | |
download | chat-6d10b103189168c556456319115774b41ee5ac73.tar.gz chat-6d10b103189168c556456319115774b41ee5ac73.tar.bz2 chat-6d10b103189168c556456319115774b41ee5ac73.zip |
Replaced MentionList and Mention components with AtMentionProvider
Diffstat (limited to 'web/react/components/search_suggestion_list.jsx')
-rw-r--r-- | web/react/components/search_suggestion_list.jsx | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/web/react/components/search_suggestion_list.jsx b/web/react/components/search_suggestion_list.jsx new file mode 100644 index 000000000..739b7199d --- /dev/null +++ b/web/react/components/search_suggestion_list.jsx @@ -0,0 +1,86 @@ +// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +import Constants from '../utils/constants.jsx'; +import SuggestionList from './suggestion_list.jsx'; +import * as Utils from '../utils/utils.jsx'; + +export default class SearchSuggestionList extends SuggestionList { + componentDidUpdate(prevProps, prevState) { + if (this.state.items.length > 0 && prevState.items.length === 0) { + this.getContent().perfectScrollbar(); + } + } + + getContent() { + return $(ReactDOM.findDOMNode(this.refs.popover)).find('.popover-content'); + } + + renderChannelDivider(type) { + let text; + if (type === Constants.OPEN_CHANNEL) { + text = 'Public ' + Utils.getChannelTerm(type) + 's'; + } else { + text = 'Private ' + Utils.getChannelTerm(type) + 's'; + } + + return ( + <div + key={type + '-divider'} + className='search-autocomplete__divider' + > + <span>{text}</span> + </div> + ); + } + + render() { + if (this.state.items.length === 0) { + return null; + } + + const items = []; + for (let i = 0; i < this.state.items.length; i++) { + const item = this.state.items[i]; + const term = this.state.terms[i]; + const isSelection = term === this.state.selection; + + // ReactComponent names need to be upper case when used in JSX + const Component = this.state.components[i]; + + // temporary hack to add dividers between public and private channels in the search suggestion list + if (i === 0 || item.type !== this.state.items[i - 1].type) { + if (item.type === Constants.OPEN_CHANNEL) { + items.push(this.renderChannelDivider(Constants.OPEN_CHANNEL)); + } else if (item.type === Constants.PRIVATE_CHANNEL) { + items.push(this.renderChannelDivider(Constants.PRIVATE_CHANNEL)); + } + } + + items.push( + <Component + key={term} + ref={term} + item={item} + isSelection={isSelection} + onClick={this.handleItemClick.bind(this, term)} + /> + ); + } + + return ( + <ReactBootstrap.Popover + ref='popover' + id='search-autocomplete__popover' + className='search-help-popover autocomplete visible' + placement='bottom' + > + {items} + </ReactBootstrap.Popover> + ); + } +} + +SearchSuggestionList.propTypes = { + suggestionId: React.PropTypes.string.isRequired +}; |