Merge pull request #1457 from hmhealey/plt729

PLT-729 Added search button to mobile header
Этот коммит содержится в:
Christopher Speller
2015-11-19 08:08:28 -05:00
родитель 0dbbdaa45e 70c957d454
Коммит 5f848b7479
6 изменённых файлов: 78 добавлений и 10 удалений

Просмотреть файл

@@ -32,6 +32,7 @@ export default class Navbar extends React.Component {
this.onChange = this.onChange.bind(this); this.onChange = this.onChange.bind(this);
this.handleLeave = this.handleLeave.bind(this); this.handleLeave = this.handleLeave.bind(this);
this.showSearch = this.showSearch.bind(this);
this.createCollapseButtons = this.createCollapseButtons.bind(this); this.createCollapseButtons = this.createCollapseButtons.bind(this);
this.createDropdown = this.createDropdown.bind(this); this.createDropdown = this.createDropdown.bind(this);
@@ -100,6 +101,11 @@ export default class Navbar extends React.Component {
$('.inner__wrap').toggleClass('move--left-small'); $('.inner__wrap').toggleClass('move--left-small');
$('.sidebar--menu').toggleClass('move--left'); $('.sidebar--menu').toggleClass('move--left');
} }
showSearch() {
AppDispatcher.handleServerAction({
type: ActionTypes.SHOW_SEARCH
});
}
onChange() { onChange() {
this.setState(this.getStateFromStores()); this.setState(this.getStateFromStores());
$('#navbar .navbar-brand .description').popover({placement: 'bottom', trigger: 'click', html: true}); $('#navbar .navbar-brand .description').popover({placement: 'bottom', trigger: 'click', html: true});
@@ -411,6 +417,16 @@ export default class Navbar extends React.Component {
var collapseButtons = this.createCollapseButtons(currentId); var collapseButtons = this.createCollapseButtons(currentId);
const searchButton = (
<button
type='button'
className='navbar-toggle pull-right'
onClick={this.showSearch}
>
<span className='glyphicon glyphicon-search icon--white' />
</button>
);
var channelMenuDropdown = this.createDropdown(channel, channelTitle, isAdmin, isDirect, popoverContent); var channelMenuDropdown = this.createDropdown(channel, channelTitle, isAdmin, isDirect, popoverContent);
return ( return (
@@ -422,6 +438,7 @@ export default class Navbar extends React.Component {
<div className='container-fluid theme'> <div className='container-fluid theme'>
<div className='navbar-header'> <div className='navbar-header'>
{collapseButtons} {collapseButtons}
{searchButton}
{channelMenuDropdown} {channelMenuDropdown}
</div> </div>
</div> </div>

Просмотреть файл

@@ -80,14 +80,27 @@ export default class SearchResults extends React.Component {
var ctls = null; var ctls = null;
if (noResults) { if (!searchTerm && noResults) {
ctls = (
<div className='sidebar--right__subheader'>
<ul>
<li>
{'Use '}<b>{'"quotation marks"'}</b>{' to search for phrases'}
</li>
<li>
{'Use '}<b>{'from:'}</b>{' to find posts from specific users and '}<b>{'in:'}</b>{' to find posts in specific channels'}
</li>
</ul>
</div>
);
} else if (noResults) {
ctls = ctls =
( (
<div className='sidebar--right__subheader'> <div className='sidebar--right__subheader'>
<h4>{'NO RESULTS'}</h4> <h4>{'NO RESULTS'}</h4>
<ul> <ul>
<li>If you're searching a partial phrase (ex. searching "rea", looking for "reach" or "reaction"), append a * to your search term</li> <li>{'If you\'re searching a partial phrase (ex. searching "rea", looking for "reach" or "reaction"), append a * to your search term'}</li>
<li>Due to the volume of results, two letter searches and common words like "this", "a" and "is" won't appear in search results</li> <li>{'Due to the volume of results, two letter searches and common words like "this", "a" and "is" won\'t appear in search results'}</li>
</ul> </ul>
</div> </div>
); );

Просмотреть файл

@@ -7,10 +7,6 @@ var SearchStore = require('../stores/search_store.jsx');
var PostStore = require('../stores/post_store.jsx'); var PostStore = require('../stores/post_store.jsx');
var Utils = require('../utils/utils.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 { export default class SidebarRight extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
@@ -19,19 +15,29 @@ export default class SidebarRight extends React.Component {
this.onSelectedChange = this.onSelectedChange.bind(this); this.onSelectedChange = this.onSelectedChange.bind(this);
this.onSearchChange = this.onSearchChange.bind(this); this.onSearchChange = this.onSearchChange.bind(this);
this.onShowSearch = this.onShowSearch.bind(this);
this.doStrangeThings = this.doStrangeThings.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() { componentDidMount() {
SearchStore.addSearchChangeListener(this.onSearchChange); SearchStore.addSearchChangeListener(this.onSearchChange);
PostStore.addSelectedPostChangeListener(this.onSelectedChange); PostStore.addSelectedPostChangeListener(this.onSelectedChange);
SearchStore.addShowSearchListener(this.onShowSearch);
this.doStrangeThings(); this.doStrangeThings();
} }
componentWillUnmount() { componentWillUnmount() {
SearchStore.removeSearchChangeListener(this.onSearchChange); SearchStore.removeSearchChangeListener(this.onSearchChange);
PostStore.removeSelectedPostChangeListener(this.onSelectedChange); PostStore.removeSelectedPostChangeListener(this.onSelectedChange);
SearchStore.removeShowSearchListener(this.onShowSearch);
} }
componentWillUpdate() { componentWillUpdate() {
PostStore.jumpPostsViewSidebarOpen(); PostStore.jumpPostsViewSidebarOpen();
@@ -64,18 +70,25 @@ export default class SidebarRight extends React.Component {
this.doStrangeThings(); this.doStrangeThings();
} }
onSelectedChange(fromSearch) { onSelectedChange(fromSearch) {
var newState = getStateFromStores(fromSearch); var newState = this.getStateFromStores(fromSearch);
newState.from_search = fromSearch; newState.from_search = fromSearch;
if (!Utils.areObjectsEqual(newState, this.state)) { if (!Utils.areObjectsEqual(newState, this.state)) {
this.setState(newState); this.setState(newState);
} }
} }
onSearchChange() { onSearchChange() {
var newState = getStateFromStores(); var newState = this.getStateFromStores();
if (!Utils.areObjectsEqual(newState, this.state)) { if (!Utils.areObjectsEqual(newState, this.state)) {
this.setState(newState); this.setState(newState);
} }
} }
onShowSearch() {
if (!this.state.search_visible) {
this.setState({
search_visible: true
});
}
}
render() { render() {
var content = ''; var content = '';

Просмотреть файл

@@ -14,6 +14,7 @@ var SEARCH_CHANGE_EVENT = 'search_change';
var SEARCH_TERM_CHANGE_EVENT = 'search_term_change'; var SEARCH_TERM_CHANGE_EVENT = 'search_term_change';
var MENTION_DATA_CHANGE_EVENT = 'mention_data_change'; var MENTION_DATA_CHANGE_EVENT = 'mention_data_change';
var ADD_MENTION_EVENT = 'add_mention'; var ADD_MENTION_EVENT = 'add_mention';
var SHOW_SEARCH_EVENT = 'show_search';
class SearchStoreClass extends EventEmitter { class SearchStoreClass extends EventEmitter {
constructor() { constructor() {
@@ -35,6 +36,10 @@ class SearchStoreClass extends EventEmitter {
this.addMentionDataChangeListener = this.addMentionDataChangeListener.bind(this); this.addMentionDataChangeListener = this.addMentionDataChangeListener.bind(this);
this.removeMentionDataChangeListener = this.removeMentionDataChangeListener.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.getSearchResults = this.getSearchResults.bind(this);
this.getIsMentionSearch = this.getIsMentionSearch.bind(this); this.getIsMentionSearch = this.getIsMentionSearch.bind(this);
@@ -80,6 +85,18 @@ class SearchStoreClass extends EventEmitter {
this.removeListener(SEARCH_TERM_CHANGE_EVENT, callback); 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() { getSearchResults() {
return BrowserStore.getItem('search_results'); return BrowserStore.getItem('search_results');
} }
@@ -146,6 +163,9 @@ SearchStore.dispatchToken = AppDispatcher.register((payload) => {
case ActionTypes.RECIEVED_ADD_MENTION: case ActionTypes.RECIEVED_ADD_MENTION:
SearchStore.emitAddMention(action.id, action.username); SearchStore.emitAddMention(action.id, action.username);
break; break;
case ActionTypes.SHOW_SEARCH:
SearchStore.emitShowSearch();
break;
default: default:
} }
}); });

Просмотреть файл

@@ -39,6 +39,8 @@ module.exports = {
RECIEVED_LOGS: null, RECIEVED_LOGS: null,
RECIEVED_ALL_TEAMS: null, RECIEVED_ALL_TEAMS: null,
SHOW_SEARCH: null,
TOGGLE_IMPORT_THEME_MODAL: null, TOGGLE_IMPORT_THEME_MODAL: null,
TOGGLE_INVITE_MEMBER_MODAL: null, TOGGLE_INVITE_MEMBER_MODAL: null,
TOGGLE_DELETE_POST_MODAL: null TOGGLE_DELETE_POST_MODAL: null

Просмотреть файл

@@ -33,6 +33,9 @@
background: #fff; background: #fff;
width: 21px; width: 21px;
} }
.icon--white {
color: #fff;
}
&:hover, &:active, &:focus { &:hover, &:active, &:focus {
background: inherit; background: inherit;
} }