Skip to content

Commit

Permalink
* #24. prevent multiple clicks per 2.5 sec - avg sort for V8
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurkushman committed Mar 22, 2017
1 parent 4c15062 commit 359c0fb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/components/CommonConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ module.exports = {
TIMEOUT_SEARCH: 300,
MORE_PAGES: 5,
DISPLAY_TOP: 'top',
DISPLAY_BOTTOM: 'bottom'
DISPLAY_BOTTOM: 'bottom',
SORT_PERIOD: 2500
}
25 changes: 16 additions & 9 deletions src/components/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ class Main extends React.Component {
if (this.state.discreteFocus === true) {
return;
}

const { columns } = this.settings;
if (typeof e === CommonConstants.UNDEFINED) { // on start-up - setting default
let sortedButtons = [];
Expand All @@ -376,6 +377,10 @@ class Main extends React.Component {
sortButtons : sortedButtons
});
} else { // clicked
this.nowMillis = (new Date()).getTime();
let period = this.nowMillis - this.lastTimeKeyup;

if (period > CommonConstants.SORT_PERIOD) {
this.props.children.map((th, idx) => {
var that = this;
const { sortButtons, dataSearch } = that.state;
Expand All @@ -388,15 +393,15 @@ class Main extends React.Component {
sJson = dataSearch;
}
// check and sort for other columns
if (typeof sortButtons[data] !== CommonConstants.UNDEFINED
&& sortButtons[data] !== 0
&& data !== indexData) {
if (sortButtons[data] === 1) {
sJson = this.sortAsc(data, sJson);
} else {
sJson = this.sortDesc(data, sJson);
}
}
// if (typeof sortButtons[data] !== CommonConstants.UNDEFINED
// && sortButtons[data] !== 0
// && data !== indexData) {
// if (sortButtons[data] === 1) {
// sJson = this.sortAsc(data, sJson);
// } else {
// sJson = this.sortDesc(data, sJson);
// }
// }

if (indexData === data) { // iff the cols match
if (sortButtons[data] === 1) {
Expand All @@ -409,6 +414,8 @@ class Main extends React.Component {
that.createTable(sJson, sortedButtons);
}
});
}
this.lastTimeKeyup = this.nowMillis;
}
}

Expand Down

0 comments on commit 359c0fb

Please sign in to comment.