Added ability to open search sidebar programatically
Этот коммит содержится в:
@@ -7,10 +7,6 @@ var SearchStore = require('../stores/search_store.jsx');
|
||||
var PostStore = require('../stores/post_store.jsx');
|
||||
var Utils = require('../utils/utils.jsx');
|
||||
|
||||
function getStateFromStores() {
|
||||
return {search_visible: SearchStore.getSearchResults() != null, post_right_visible: PostStore.getSelectedPost() != null, is_mention_search: SearchStore.getIsMentionSearch()};
|
||||
}
|
||||
|
||||
export default class SidebarRight extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
@@ -19,19 +15,29 @@ export default class SidebarRight extends React.Component {
|
||||
|
||||
this.onSelectedChange = this.onSelectedChange.bind(this);
|
||||
this.onSearchChange = this.onSearchChange.bind(this);
|
||||
this.onShowSearch = this.onShowSearch.bind(this);
|
||||
|
||||
this.doStrangeThings = this.doStrangeThings.bind(this);
|
||||
|
||||
this.state = getStateFromStores();
|
||||
this.state = this.getStateFromStores();
|
||||
}
|
||||
getStateFromStores() {
|
||||
return {
|
||||
search_visible: SearchStore.getSearchResults() != null,
|
||||
post_right_visible: PostStore.getSelectedPost() != null,
|
||||
is_mention_search: SearchStore.getIsMentionSearch()
|
||||
};
|
||||
}
|
||||
componentDidMount() {
|
||||
SearchStore.addSearchChangeListener(this.onSearchChange);
|
||||
PostStore.addSelectedPostChangeListener(this.onSelectedChange);
|
||||
SearchStore.addShowSearchListener(this.onShowSearch);
|
||||
this.doStrangeThings();
|
||||
}
|
||||
componentWillUnmount() {
|
||||
SearchStore.removeSearchChangeListener(this.onSearchChange);
|
||||
PostStore.removeSelectedPostChangeListener(this.onSelectedChange);
|
||||
SearchStore.removeShowSearchListener(this.onShowSearch);
|
||||
}
|
||||
componentWillUpdate() {
|
||||
PostStore.jumpPostsViewSidebarOpen();
|
||||
@@ -64,18 +70,25 @@ export default class SidebarRight extends React.Component {
|
||||
this.doStrangeThings();
|
||||
}
|
||||
onSelectedChange(fromSearch) {
|
||||
var newState = getStateFromStores(fromSearch);
|
||||
var newState = this.getStateFromStores(fromSearch);
|
||||
newState.from_search = fromSearch;
|
||||
if (!Utils.areObjectsEqual(newState, this.state)) {
|
||||
this.setState(newState);
|
||||
}
|
||||
}
|
||||
onSearchChange() {
|
||||
var newState = getStateFromStores();
|
||||
var newState = this.getStateFromStores();
|
||||
if (!Utils.areObjectsEqual(newState, this.state)) {
|
||||
this.setState(newState);
|
||||
}
|
||||
}
|
||||
onShowSearch() {
|
||||
if (!this.state.search_visible) {
|
||||
this.setState({
|
||||
search_visible: true
|
||||
});
|
||||
}
|
||||
}
|
||||
render() {
|
||||
var content = '';
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ var SEARCH_CHANGE_EVENT = 'search_change';
|
||||
var SEARCH_TERM_CHANGE_EVENT = 'search_term_change';
|
||||
var MENTION_DATA_CHANGE_EVENT = 'mention_data_change';
|
||||
var ADD_MENTION_EVENT = 'add_mention';
|
||||
var SHOW_SEARCH_EVENT = 'show_search';
|
||||
|
||||
class SearchStoreClass extends EventEmitter {
|
||||
constructor() {
|
||||
@@ -35,6 +36,10 @@ class SearchStoreClass extends EventEmitter {
|
||||
this.addMentionDataChangeListener = this.addMentionDataChangeListener.bind(this);
|
||||
this.removeMentionDataChangeListener = this.removeMentionDataChangeListener.bind(this);
|
||||
|
||||
this.emitShowSearch = this.emitShowSearch.bind(this);
|
||||
this.addShowSearchListener = this.addShowSearchListener.bind(this);
|
||||
this.removeShowSearchListener = this.removeShowSearchListener.bind(this);
|
||||
|
||||
this.getSearchResults = this.getSearchResults.bind(this);
|
||||
this.getIsMentionSearch = this.getIsMentionSearch.bind(this);
|
||||
|
||||
@@ -80,6 +85,18 @@ class SearchStoreClass extends EventEmitter {
|
||||
this.removeListener(SEARCH_TERM_CHANGE_EVENT, callback);
|
||||
}
|
||||
|
||||
emitShowSearch() {
|
||||
this.emit(SHOW_SEARCH_EVENT);
|
||||
}
|
||||
|
||||
addShowSearchListener(callback) {
|
||||
this.on(SHOW_SEARCH_EVENT, callback);
|
||||
}
|
||||
|
||||
removeShowSearchListener(callback) {
|
||||
this.removeListener(SHOW_SEARCH_EVENT, callback);
|
||||
}
|
||||
|
||||
getSearchResults() {
|
||||
return BrowserStore.getItem('search_results');
|
||||
}
|
||||
@@ -146,6 +163,9 @@ SearchStore.dispatchToken = AppDispatcher.register((payload) => {
|
||||
case ActionTypes.RECIEVED_ADD_MENTION:
|
||||
SearchStore.emitAddMention(action.id, action.username);
|
||||
break;
|
||||
case ActionTypes.SHOW_SEARCH:
|
||||
SearchStore.emitShowSearch();
|
||||
break;
|
||||
default:
|
||||
}
|
||||
});
|
||||
|
||||
@@ -39,6 +39,8 @@ module.exports = {
|
||||
RECIEVED_LOGS: null,
|
||||
RECIEVED_ALL_TEAMS: null,
|
||||
|
||||
SHOW_SEARCH: null,
|
||||
|
||||
TOGGLE_IMPORT_THEME_MODAL: null,
|
||||
TOGGLE_INVITE_MEMBER_MODAL: null
|
||||
}),
|
||||
|
||||
Ссылка в новой задаче
Block a user