Skip to content

Commit

Permalink
Fix spotlight being called multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego committed Nov 5, 2018
1 parent 2af94de commit 28d64e7
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 65 deletions.
2 changes: 1 addition & 1 deletion packages/rocketchat-ui-master/client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Template.body.onRendered(function() {
if ((e.keyCode === 80 || e.keyCode === 75) && (e.ctrlKey === true || e.metaKey === true) && e.shiftKey === false) {
e.preventDefault();
e.stopPropagation();
toolbarSearch.focus(true);
toolbarSearch.show(true);
}
const unread = Session.get('unread');
if (e.keyCode === 27 && e.shiftKey === true && (unread != null) && unread !== '') {
Expand Down
6 changes: 4 additions & 2 deletions packages/rocketchat-ui-message/client/popup/messagePopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ Template.messagePopup.onCreated(function() {
}
};
template.verifySelection = () => {
if (!template.open.curValue) {
return;
}
const current = template.find('.popup-item.selected');
if (current == null) {
const first = template.find('.popup-item');
Expand Down Expand Up @@ -149,7 +152,7 @@ Template.messagePopup.onCreated(function() {
template.onInputKeyup = (event) => {
if (template.closeOnEsc === true && template.open.curValue === true && event.which === keys.ESC) {
template.open.set(false);
$('.toolbar').css('display', 'none');
toolbarSearch.close();
event.preventDefault();
event.stopPropagation();
return;
Expand Down Expand Up @@ -301,7 +304,6 @@ Template.messagePopup.events({
template.value.set(this._id);
template.enterValue();
template.open.set(false);
return toolbarSearch.clear();
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ Template.messagePopupSlashCommandPreview.onCreated(function() {
template.onInputKeyup = (event) => {
if (template.open.curValue === true && event.which === keys.ESC) {
template.open.set(false);
$('.toolbar').css('display', 'none');
toolbarSearch.close();
event.preventDefault();
event.stopPropagation();
return;
Expand Down Expand Up @@ -297,7 +297,6 @@ Template.messagePopupSlashCommandPreview.events({
const template = Template.instance();
template.clickingItem = false;
template.enterKeyAction();
toolbarSearch.clear();
},
});

Expand Down
4 changes: 3 additions & 1 deletion packages/rocketchat-ui-sidenav/client/sidebarHeader.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
</button>
{{/each}}
</div>
{{> toolbar}}
{{/with}}
{{#if showToolbar}}
{{> toolbar }}
{{/if}}
</header>
</template>
37 changes: 34 additions & 3 deletions packages/rocketchat-ui-sidenav/client/sidebarHeader.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* globals popover menu */
import { Meteor } from 'meteor/meteor';
import { ReactiveVar } from 'meteor/reactive-var';
import { FlowRouter } from 'meteor/kadira:flow-router';
import { Template } from 'meteor/templating';

Expand Down Expand Up @@ -34,14 +35,41 @@ const extendedViewOption = (user) => {
return;
};

const showToolbar = new ReactiveVar(false);

const selectorSearch = '.toolbar__search .rc-input__element';
const toolbarSearch = {
shortcut: false,
clear() {
const $inputMessage = $('.js-input-message');

if (0 === $inputMessage.length) {
return;
}

$inputMessage.focus();
$(selectorSearch).val('');
},
show(fromShortcut) {
menu.open();
showToolbar.set(true);
this.shortcut = fromShortcut;
},
close() {
showToolbar.set(false);
if (this.shortcut) {
menu.close();
}
},
};

this.toolbarSearch = toolbarSearch;

const toolbarButtons = (user) => [{
name: t('Search'),
icon: 'magnifier',
action: () => {
const toolbarEl = $('.toolbar');
toolbarEl.css('display', 'block');
toolbarEl.find('.rc-input__element').focus();
toolbarSearch.show(false);
},
},
{
Expand Down Expand Up @@ -223,6 +251,9 @@ Template.sidebarHeader.helpers({
toolbarButtons() {
return toolbarButtons(Meteor.userId()).filter((button) => !button.condition || button.condition());
},
showToolbar() {
return showToolbar.get();
},
});

Template.sidebarHeader.events({
Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-ui-sidenav/client/toolbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="rc-input__icon">
{{> icon block="rc-input__icon-svg" icon="magnifier"}}
</div>
<input type="text" class="rc-input__element rc-input__element--small" placeholder="{{getPlaceholder}}">
<input type="text" class="rc-input__element rc-input__element--small js-search" placeholder="{{getPlaceholder}}">
<div class="rc-input__icon rc-input__icon--right">
{{> icon block="rc-input__icon-svg" icon="plus"}}
</div>
Expand Down
65 changes: 12 additions & 53 deletions packages/rocketchat-ui-sidenav/client/toolbar.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,19 @@
/* global menu, toolbarSearch */

/* global menu */
import { Meteor } from 'meteor/meteor';
import { ReactiveVar } from 'meteor/reactive-var';
import { Tracker } from 'meteor/tracker';
import { FlowRouter } from 'meteor/kadira:flow-router';
import { Session } from 'meteor/session';
import { Template } from 'meteor/templating';
import { TAPi18n } from 'meteor/tap:i18n';
import _ from 'underscore';

let isLoading;
let filterText = '';
let usernamesFromClient;
let resultsFromClient;

const selectorSearch = '.toolbar__search .rc-input__element';
Meteor.startup(() => {
isLoading = new ReactiveVar(false);
});

const toolbarSearch = {
shortcut: false,
clear() {
const $inputMessage = $('.js-input-message');

if (0 === $inputMessage.length) {
return;
}

$inputMessage.focus();
$(selectorSearch).val('');

if (this.shortcut) {
menu.close();
}
},
focus(fromShortcut) {
menu.open();
$('.toolbar').css('display', 'block');
$(selectorSearch).focus();
this.shortcut = fromShortcut;
},
};

this.toolbarSearch = toolbarSearch;
const isLoading = new ReactiveVar(false);
const open = new ReactiveVar(false);

const getFromServer = (cb, type) => {
isLoading.set(true);
Expand Down Expand Up @@ -118,14 +88,6 @@ Template.toolbar.helpers({
return placeholder;
},
popupConfig() {
const open = new ReactiveVar(false);

Tracker.autorun(() => {
if (open.get() === false) {
toolbarSearch.clear();
}
});

const config = {
cls: 'search-results-list',
collection: Meteor.userId() ? RocketChat.models.Subscriptions : RocketChat.models.Rooms,
Expand Down Expand Up @@ -216,28 +178,21 @@ Template.toolbar.events({
return false;
},

'click [role="search"] input'() {
toolbarSearch.shortcut = false;
},

'keyup [role="search"] input'(e) {
if (e.which === 27) {
e.preventDefault();
e.stopPropagation();

toolbarSearch.clear();
$('.toolbar').css('display', 'none');
}
},

'click [role="search"] input'() {
toolbarSearch.shortcut = false;
},

'click .toolbar__icon-search--right'() {
toolbarSearch.clear();
$('.toolbar').css('display', 'none');
},

'blur [role="search"] input'() {
toolbarSearch.clear();
$('.toolbar').css('display', 'none');
toolbarSearch.close();
},

'click [role="search"] button, touchend [role="search"] button'(e) {
Expand All @@ -250,3 +205,7 @@ Template.toolbar.events({
}
},
});

Template.toolbar.onRendered(function() {
this.$('.js-search').select().focus();
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
position: absolute;
left: 10px;

display: none;

width: 100%;
margin: 0 -10px;
padding: 0 calc(var(--sidebar-default-padding) + 10px);
Expand Down

0 comments on commit 28d64e7

Please sign in to comment.