chore: clean up range selection handler

This commit is contained in:
Akuoko Daniel Jnr 2020-11-30 16:17:48 +00:00
parent e89d029bb7
commit 77f320fdba
No known key found for this signature in database
GPG Key ID: 1C95803CACD3E9DC

View File

@ -268,25 +268,11 @@ export default class DataView extends React.Component {
let i = e.target.name;
if (this.state.isShiftDown && this.state.lastSelectedItemIndex !== i) {
const start = Math.min(i, this.state.lastSelectedItemIndex);
const stop = Math.max(i, this.state.lastSelectedItemIndex) + 1;
let rangeSelected = {};
if (checked[i]) {
for (let i = start; i < stop; i++) {
delete checked[i];
}
} else {
for (let i = start; i < stop; i++) {
rangeSelected[i] = true;
}
}
let newSelection = Object.assign({}, checked, rangeSelected);
this.setState({ checked: newSelection, lastSelectedItemIndex: i });
return;
return this._handleShiftClick({
currentSelectedItemIndex: i,
lastSelectedItemIndex: this.state.lastSelectedItemIndex,
checked,
});
}
if (e.target.value === false) {
@ -333,25 +319,11 @@ export default class DataView extends React.Component {
let checked = this.state.checked;
if (this.state.isShiftDown && this.state.lastSelectedItemIndex !== i) {
const start = Math.min(i, this.state.lastSelectedItemIndex);
const stop = Math.max(i, this.state.lastSelectedItemIndex) + 1;
let rangeSelected = {};
if (checked[i]) {
for (let i = start; i < stop; i++) {
delete checked[i];
}
} else {
for (let i = start; i < stop; i++) {
rangeSelected[i] = true;
}
}
let newSelection = Object.assign({}, checked, rangeSelected);
this.setState({ checked: newSelection, lastSelectedItemIndex: i });
return;
return this._handleShiftClick({
currentSelectedItemIndex: i,
lastSelectedItemIndex: this.state.lastSelectedItemIndex,
checked,
});
}
if (checked[i]) {
@ -362,6 +334,26 @@ export default class DataView extends React.Component {
this.setState({ checked, lastSelectedItemIndex: i });
};
_handleShiftClick = ({ currentSelectedItemIndex, lastSelectedItemIndex, checked }) => {
const start = Math.min(currentSelectedItemIndex, lastSelectedItemIndex);
const stop = Math.max(currentSelectedItemIndex, lastSelectedItemIndex) + 1;
let rangeSelected = {};
for (let i = start; i < stop; i++) {
if (checked[currentSelectedItemIndex]) {
delete checked[i];
} else {
rangeSelected[i] = true;
}
}
let newSelection = Object.assign({}, checked, rangeSelected);
this.setState({ checked: newSelection, lastSelectedItemIndex: currentSelectedItemIndex });
return;
};
_handleDelete = async (cid, id) => {
const message = `Are you sure you want to delete these files? They will be deleted from your slates as well`;
if (!window.confirm(message)) {