diff options
author | =Corey Hulen <corey@hulen.com> | 2015-06-14 23:53:32 -0800 |
---|---|---|
committer | =Corey Hulen <corey@hulen.com> | 2015-06-14 23:53:32 -0800 |
commit | 56e74239d6b34df8f30ef046f0b0ff4ff0866a71 (patch) | |
tree | 044da29848cf0f5c8607eac34de69065171669cf /web/react/components/sidebar_right.jsx | |
download | chat-56e74239d6b34df8f30ef046f0b0ff4ff0866a71.tar.gz chat-56e74239d6b34df8f30ef046f0b0ff4ff0866a71.tar.bz2 chat-56e74239d6b34df8f30ef046f0b0ff4ff0866a71.zip |
first commit
Diffstat (limited to 'web/react/components/sidebar_right.jsx')
-rw-r--r-- | web/react/components/sidebar_right.jsx | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/web/react/components/sidebar_right.jsx b/web/react/components/sidebar_right.jsx new file mode 100644 index 000000000..8334b345b --- /dev/null +++ b/web/react/components/sidebar_right.jsx @@ -0,0 +1,84 @@ +// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. +// See License.txt for license information. + + +var SearchResults =require('./search_results.jsx'); +var PostRight =require('./post_right.jsx'); +var PostStore = require('../stores/post_store.jsx'); +var Constants = require('../utils/constants.jsx'); +var utils = require('../utils/utils.jsx'); + +function getStateFromStores(from_search) { + return { search_visible: PostStore.getSearchResults() != null, post_right_visible: PostStore.getSelectedPost() != null, is_mention_search: PostStore.getIsMentionSearch() }; +} + +module.exports = React.createClass({ + componentDidMount: function() { + PostStore.addSearchChangeListener(this._onSearchChange); + PostStore.addSelectedPostChangeListener(this._onSelectedChange); + }, + componentWillUnmount: function() { + PostStore.removeSearchChangeListener(this._onSearchChange); + PostStore.removeSelectedPostChangeListener(this._onSelectedChange); + }, + _onSelectedChange: function(from_search) { + if (this.isMounted()) { + var newState = getStateFromStores(from_search); + newState.from_search = from_search; + if (!utils.areStatesEqual(newState, this.state)) { + this.setState(newState); + } + } + }, + _onSearchChange: function() { + if (this.isMounted()) { + var newState = getStateFromStores(); + if (!utils.areStatesEqual(newState, this.state)) { + this.setState(newState); + } + } + }, + resize: function() { + $(".post-list-holder-by-time").scrollTop(100000); + $(".post-list-holder-by-time").perfectScrollbar('update'); + }, + getInitialState: function() { + return getStateFromStores(); + }, + render: function() { + if (! (this.state.search_visible || this.state.post_right_visible)) { + $('.inner__wrap').removeClass('move--left').removeClass('move--right'); + $('.sidebar--right').removeClass('move--left'); + this.resize(); + return ( + <div></div> + ); + } + + $('.inner__wrap').removeClass('.move--right').addClass('move--left'); + $('.sidebar--left').removeClass('move--right'); + $('.sidebar--right').addClass('move--left'); + $('.sidebar--right').prepend('<div class="sidebar__overlay"></div>'); + this.resize(); + setTimeout(function(){ + $('.sidebar__overlay').fadeOut("200", function(){ + $(this).remove(); + }); + },500) + + var content = ""; + + if (this.state.search_visible) { + content = <SearchResults isMentionSearch={this.state.is_mention_search} />; + } + else if (this.state.post_right_visible) { + content = <PostRight fromSearch={this.state.from_search} isMentionSearch={this.state.is_mention_search} />; + } + + return ( + <div className="sidebar-right-container"> + { content } + </div> + ); + } +}); |