From cf7a05f80f68b5b1c8bcc0089679dd497cec2506 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Sun, 14 Jun 2015 23:53:32 -0800 Subject: first commit --- web/react/components/search_results.jsx | 180 ++++++++++++++++++++++++++++++++ 1 file changed, 180 insertions(+) create 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 new file mode 100644 index 000000000..51aefd3b8 --- /dev/null +++ b/web/react/components/search_results.jsx @@ -0,0 +1,180 @@ +// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. +// See License.txt for license information. + + +var PostStore = require('../stores/post_store.jsx'); +var ChannelStore = require('../stores/channel_store.jsx'); +var UserStore = require('../stores/user_store.jsx'); +var UserProfile = require( './user_profile.jsx' ); +var SearchBox =require('./search_bar.jsx'); +var utils = require('../utils/utils.jsx'); +var client =require('../utils/client.jsx'); +var AppDispatcher = require('../dispatcher/app_dispatcher.jsx'); +var Constants = require('../utils/constants.jsx'); +var ActionTypes = Constants.ActionTypes; + +RhsHeaderSearch = React.createClass({ + handleClose: function(e) { + e.preventDefault(); + + AppDispatcher.handleServerAction({ + type: ActionTypes.RECIEVED_SEARCH, + results: null + }); + + AppDispatcher.handleServerAction({ + type: ActionTypes.RECIEVED_POST_SELECTED, + results: null + }); + }, + render: function() { + var title = this.props.isMentionSearch ? "Recent Mentions" : "Search Results"; + return ( +
+ {title} + +
+ ); + } +}); + +SearchItem = React.createClass({ + handleClick: function(e) { + e.preventDefault(); + + var self = this; + client.getPost( + this.props.post.channel_id, + this.props.post.id, + function(data) { + + AppDispatcher.handleServerAction({ + type: ActionTypes.RECIEVED_POST_SELECTED, + post_list: data, + from_search: PostStore.getSearchTerm() + }); + + AppDispatcher.handleServerAction({ + type: ActionTypes.RECIEVED_SEARCH, + results: null, + is_mention_search: self.props.isMentionSearch + }); + }, + function(err) { + dispatchError(err, "getPost"); + } + ); + }, + render: function() { + + var message = utils.textToJsx(this.props.post.message, {searchTerm: this.props.term, noMentionHighlight: !this.props.isMentionSearch}); + var channelName = ""; + var channel = ChannelStore.get(this.props.post.channel_id) + + if (channel) { + if (channel.type === 'D') { + channelName = "Direct Message"; + } else { + channelName = channel.display_name; + } + } + + return ( +
+
{ channelName }
+
+ +
+
+
    +
  • +
  • +
+
{message}
+
+
+ ); + } +}); + +function getStateFromStores() { + return { results: PostStore.getSearchResults() }; +} + +module.exports = React.createClass({ + componentDidMount: function() { + PostStore.addSearchChangeListener(this._onChange); + this.resize(); + var self = this; + $(window).resize(function(){ + self.resize(); + }); + }, + componentDidUpdate: function() { + this.resize(); + }, + componentWillUnmount: function() { + PostStore.removeSearchChangeListener(this._onChange); + }, + _onChange: function() { + if (this.isMounted()) { + var newState = getStateFromStores(); + if (!utils.areStatesEqual(newState, this.state)) { + this.setState(newState); + } + } + }, + getInitialState: function() { + return getStateFromStores(); + }, + resize: function() { + var height = $(window).height() - $('#error_bar').outerHeight() - 100; + $("#search-items-container").css("height", height + "px"); + $("#search-items-container").scrollTop(0); + $("#search-items-container").perfectScrollbar(); + }, + render: function() { + + var results = this.state.results; + var currentId = UserStore.getCurrentId(); + var searchForm = currentId == null ? null : ; + + if (results == null) { + return ( +
+
Search Results
+
+ ); + } + + if (!results.order || results.order.length == 0) { + return ( +
+
{searchForm}
+
+ +
+
No results
+
+
+
+ ); + } + + var self = this; + return ( +
+
{searchForm}
+
+ +
+ {results.order.map(function(id) { + var post = results.posts[id]; + return + })} +
+
+
+ ); + } +}); -- cgit v1.2.3-1-g7c22