From 12896bd23eeba79884245c1c29fdc568cf21a7fa Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Mon, 14 Mar 2016 08:50:46 -0400 Subject: Converting to Webpack. Stage 1. --- web/react/components/search_results.jsx | 193 -------------------------------- 1 file changed, 193 deletions(-) delete mode 100644 web/react/components/search_results.jsx (limited to 'web/react/components/search_results.jsx') diff --git a/web/react/components/search_results.jsx b/web/react/components/search_results.jsx deleted file mode 100644 index 8985063a0..000000000 --- a/web/react/components/search_results.jsx +++ /dev/null @@ -1,193 +0,0 @@ -// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -import ChannelStore from '../stores/channel_store.jsx'; -import SearchStore from '../stores/search_store.jsx'; -import UserStore from '../stores/user_store.jsx'; -import SearchBox from './search_bar.jsx'; -import * as Utils from '../utils/utils.jsx'; -import SearchResultsHeader from './search_results_header.jsx'; -import SearchResultsItem from './search_results_item.jsx'; - -import {FormattedMessage, FormattedHTMLMessage} from 'mm-intl'; - -function getStateFromStores() { - const results = SearchStore.getSearchResults(); - - const channels = new Map(); - - if (results && results.order) { - const channelIds = results.order.map((postId) => results.posts[postId].channel_id); - for (const id of channelIds) { - if (channels.has(id)) { - continue; - } - - channels.set(id, ChannelStore.get(id)); - } - } - - return { - results, - channels - }; -} - -export default class SearchResults extends React.Component { - constructor(props) { - super(props); - - this.mounted = false; - - this.onChange = this.onChange.bind(this); - this.onUserChange = this.onUserChange.bind(this); - this.resize = this.resize.bind(this); - this.handleResize = this.handleResize.bind(this); - - const state = getStateFromStores(); - state.windowWidth = Utils.windowWidth(); - state.windowHeight = Utils.windowHeight(); - state.profiles = JSON.parse(JSON.stringify(UserStore.getProfiles())); - this.state = state; - } - - componentDidMount() { - this.mounted = true; - SearchStore.addSearchChangeListener(this.onChange); - ChannelStore.addChangeListener(this.onChange); - UserStore.addChangeListener(this.onUserChange); - this.resize(); - window.addEventListener('resize', this.handleResize); - } - - shouldComponentUpdate(nextProps, nextState) { - if (!Utils.areObjectsEqual(this.props, nextProps)) { - return true; - } - - if (!Utils.areObjectsEqual(this.state, nextState)) { - return true; - } - - return false; - } - - componentDidUpdate() { - this.resize(); - } - - componentWillUnmount() { - SearchStore.removeSearchChangeListener(this.onChange); - ChannelStore.removeChangeListener(this.onChange); - UserStore.removeChangeListener(this.onUserChange); - this.mounted = false; - window.removeEventListener('resize', this.handleResize); - } - - handleResize() { - this.setState({ - windowWidth: Utils.windowWidth(), - windowHeight: Utils.windowHeight() - }); - } - - onChange() { - if (this.mounted) { - this.setState(getStateFromStores()); - } - } - - onUserChange() { - this.setState({profiles: JSON.parse(JSON.stringify(UserStore.getProfiles()))}); - } - - resize() { - $('#search-items-container').scrollTop(0); - if (this.state.windowWidth > 768) { - $('#search-items-container').perfectScrollbar(); - } - } - - render() { - var results = this.state.results; - var currentId = UserStore.getCurrentId(); - var searchForm = null; - if (currentId) { - searchForm = ; - } - var noResults = (!results || !results.order || !results.order.length); - var searchTerm = SearchStore.getSearchTerm(); - const profiles = this.state.profiles || {}; - - var ctls = null; - - if (!searchTerm && noResults) { - ctls = ( -
- -
- ); - } else if (noResults) { - ctls = - ( -
-

- -

- -
- ); - } else { - ctls = results.order.map(function mymap(id) { - const post = results.posts[id]; - let profile; - if (UserStore.getCurrentId() === post.user_id) { - profile = UserStore.getCurrentUser(); - } else { - profile = profiles[post.user_id]; - } - return ( - - ); - }, this); - } - - return ( -
-
{searchForm}
-
- -
- {ctls} -
-
-
- ); - } -} - -SearchResults.propTypes = { - isMentionSearch: React.PropTypes.bool -}; -- cgit v1.2.3-1-g7c22