First commit for toggling mentions using shortcut and button (#4169)

Also did some refactoring and moved code to actions

Fixed coding style errors
Этот коммит содержится в:
Pepijn
2016-10-11 15:07:38 +02:00
коммит произвёл Joram Wilander
родитель 6e9e41ebb5
Коммит 944bb1ba61
6 изменённых файлов: 82 добавлений и 73 удалений

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

@@ -487,3 +487,49 @@ export function emitJoinChannelEvent(channel, success, failure) {
failure failure
); );
} }
export function emitSearchMentionsEvent(user) {
let terms = '';
if (user.notify_props && user.notify_props.mention_keys) {
const termKeys = UserStore.getMentionKeys(user.id);
if (termKeys.indexOf('@channel') !== -1) {
termKeys[termKeys.indexOf('@channel')] = '';
}
if (termKeys.indexOf('@all') !== -1) {
termKeys[termKeys.indexOf('@all')] = '';
}
terms = termKeys.join(' ');
}
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_SEARCH_TERM,
term: terms,
do_search: true,
is_mention_search: true
});
}
export function toggleSideBarAction(visible) {
if (!visible) {
//Array of actions resolving in the closing of the sidebar
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_SEARCH,
results: null
});
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_SEARCH_TERM,
term: null,
do_search: false,
is_mention_search: false
});
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_POST_SELECTED,
postId: null
});
}
}

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

@@ -50,7 +50,7 @@ export default class ChannelHeader extends React.Component {
this.searchMentions = this.searchMentions.bind(this); this.searchMentions = this.searchMentions.bind(this);
this.showRenameChannelModal = this.showRenameChannelModal.bind(this); this.showRenameChannelModal = this.showRenameChannelModal.bind(this);
this.hideRenameChannelModal = this.hideRenameChannelModal.bind(this); this.hideRenameChannelModal = this.hideRenameChannelModal.bind(this);
this.openRecentMentions = this.openRecentMentions.bind(this); this.handleShortcut = this.handleShortcut.bind(this);
this.getFlagged = this.getFlagged.bind(this); this.getFlagged = this.getFlagged.bind(this);
this.initWebrtc = this.initWebrtc.bind(this); this.initWebrtc = this.initWebrtc.bind(this);
this.onBusy = this.onBusy.bind(this); this.onBusy = this.onBusy.bind(this);
@@ -97,7 +97,7 @@ export default class ChannelHeader extends React.Component {
WebrtcStore.addChangedListener(this.onListenerChange); WebrtcStore.addChangedListener(this.onListenerChange);
WebrtcStore.addBusyListener(this.onBusy); WebrtcStore.addBusyListener(this.onBusy);
$('.sidebar--left .dropdown-menu').perfectScrollbar(); $('.sidebar--left .dropdown-menu').perfectScrollbar();
document.addEventListener('keydown', this.openRecentMentions); document.addEventListener('keydown', this.handleShortcut);
} }
componentWillUnmount() { componentWillUnmount() {
@@ -109,7 +109,7 @@ export default class ChannelHeader extends React.Component {
UserStore.removeStatusesChangeListener(this.onListenerChange); UserStore.removeStatusesChangeListener(this.onListenerChange);
WebrtcStore.removeChangedListener(this.onListenerChange); WebrtcStore.removeChangedListener(this.onListenerChange);
WebrtcStore.removeBusyListener(this.onBusy); WebrtcStore.removeBusyListener(this.onBusy);
document.removeEventListener('keydown', this.openRecentMentions); document.removeEventListener('keydown', this.handleShortcut);
} }
shouldComponentUpdate(nextProps) { shouldComponentUpdate(nextProps) {
@@ -142,41 +142,35 @@ export default class ChannelHeader extends React.Component {
searchMentions(e) { searchMentions(e) {
e.preventDefault(); e.preventDefault();
const user = this.state.currentUser; const user = this.state.currentUser;
if (SearchStore.isMentionSearch) {
let terms = ''; // Close
if (user.notify_props && user.notify_props.mention_keys) { GlobalActions.toggleSideBarAction(false);
const termKeys = UserStore.getMentionKeys(user.id); } else {
GlobalActions.emitSearchMentionsEvent(user);
if (termKeys.indexOf('@channel') !== -1) {
termKeys[termKeys.indexOf('@channel')] = '';
}
if (termKeys.indexOf('@all') !== -1) {
termKeys[termKeys.indexOf('@all')] = '';
}
terms = termKeys.join(' ');
} }
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_SEARCH_TERM,
term: terms,
do_search: true,
is_mention_search: true
});
} }
getFlagged(e) { getFlagged(e) {
e.preventDefault(); e.preventDefault();
getFlaggedPosts(); if (SearchStore.isFlaggedPosts) {
GlobalActions.toggleSideBarAction(false);
} else {
getFlaggedPosts();
}
} }
openRecentMentions(e) { handleShortcut(e) {
if (Utils.cmdOrCtrlPressed(e) && e.shiftKey && e.keyCode === Constants.KeyCodes.M) { if (Utils.cmdOrCtrlPressed(e) && e.shiftKey) {
e.preventDefault(); e.preventDefault();
this.searchMentions(e); if (e.keyCode === Constants.KeyCodes.M) {
this.searchMentions(e);
}
//@TODO create shortcut for toggling flagged posts
// else if (e.keyCode == Constants.KeyCodes.<keycode>) {
// this.toggleFlagged();
// }
} }
} }

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

@@ -1,14 +1,12 @@
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information. // See License.txt for license information.
import AppDispatcher from '../dispatcher/app_dispatcher.jsx';
import Constants from 'utils/constants.jsx'; import Constants from 'utils/constants.jsx';
import {Tooltip, OverlayTrigger} from 'react-bootstrap'; import {Tooltip, OverlayTrigger} from 'react-bootstrap';
import * as GlobalActions from 'actions/global_actions.jsx';
import {FormattedMessage} from 'react-intl'; import {FormattedMessage} from 'react-intl';
var ActionTypes = Constants.ActionTypes;
import React from 'react'; import React from 'react';
export default class SearchResultsHeader extends React.Component { export default class SearchResultsHeader extends React.Component {
@@ -22,22 +20,7 @@ export default class SearchResultsHeader extends React.Component {
handleClose(e) { handleClose(e) {
e.preventDefault(); e.preventDefault();
AppDispatcher.handleServerAction({ GlobalActions.toggleSideBarAction(false);
type: ActionTypes.RECEIVED_SEARCH,
results: null
});
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_SEARCH_TERM,
term: null,
do_search: false,
is_mention_search: false
});
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_POST_SELECTED,
postId: null
});
this.props.shrink(); this.props.shrink();
} }

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

@@ -37,6 +37,7 @@ export default class SidebarRight extends React.Component {
this.state = { this.state = {
searchVisible: SearchStore.getSearchResults() !== null, searchVisible: SearchStore.getSearchResults() !== null,
isMentionSearch: SearchStore.getIsMentionSearch(), isMentionSearch: SearchStore.getIsMentionSearch(),
isFlaggedPosts: SearchStore.getIsFlaggedPosts(),
postRightVisible: Boolean(PostStore.getSelectedPost()), postRightVisible: Boolean(PostStore.getSelectedPost()),
expanded: false, expanded: false,
fromSearch: false, fromSearch: false,
@@ -125,7 +126,9 @@ export default class SidebarRight extends React.Component {
} }
onShrink() { onShrink() {
this.setState({expanded: false}); this.setState({
expanded: false
});
} }
onSearchChange() { onSearchChange() {

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

@@ -9,6 +9,7 @@ import AboutBuildModal from './about_build_modal.jsx';
import UserStore from 'stores/user_store.jsx'; import UserStore from 'stores/user_store.jsx';
import TeamStore from 'stores/team_store.jsx'; import TeamStore from 'stores/team_store.jsx';
import SearchStore from 'stores/search_store.jsx';
import PreferenceStore from 'stores/preference_store.jsx'; import PreferenceStore from 'stores/preference_store.jsx';
import WebrtcStore from 'stores/webrtc_store.jsx'; import WebrtcStore from 'stores/webrtc_store.jsx';
@@ -92,32 +93,13 @@ export default class SidebarRightMenu extends React.Component {
searchMentions(e) { searchMentions(e) {
e.preventDefault(); e.preventDefault();
const user = this.state.currentUser; const user = this.state.currentUser;
if (SearchStore.isMentionSearch) {
let terms = ''; GlobalActions.toggleSideBarAction(false);
if (user.notify_props && user.notify_props.mention_keys) { } else {
const termKeys = UserStore.getMentionKeys(user.id); GlobalActions.emitSearchMentionsEvent(user);
this.hideSidebars();
if (termKeys.indexOf('@channel') !== -1) {
termKeys[termKeys.indexOf('@channel')] = '';
}
if (termKeys.indexOf('@all') !== -1) {
termKeys[termKeys.indexOf('@all')] = '';
}
terms = termKeys.join(' ');
} }
this.hideSidebars();
AppDispatcher.handleServerAction({
type: ActionTypes.RECEIVED_SEARCH_TERM,
term: terms,
do_search: true,
is_mention_search: true
});
} }
closeLeftSidebar() { closeLeftSidebar() {

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

@@ -19,6 +19,7 @@ class SearchStoreClass extends EventEmitter {
this.searchResults = null; this.searchResults = null;
this.isMentionSearch = false; this.isMentionSearch = false;
this.isFlaggedPosts = false; this.isFlaggedPosts = false;
this.isVisible = false;
this.searchTerm = ''; this.searchTerm = '';
} }