Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return sorted;
}
if (this.state.nameDirection === SORT_DIRECTION.DESC) {
return sorted.reverse();
}
}
if (this.state.ageDirection) {
//@ts-ignore
const sorted = DATA.slice(0).sort((a, b) => a[1] - b[1]);
if (this.state.ageDirection === SORT_DIRECTION.ASC) {
return sorted;
}
if (this.state.ageDirection === SORT_DIRECTION.DESC) {
return sorted.reverse();
}
}
return DATA;
};
handleSort = (title: string, prevDirection: DirectionT) => {
let nextDirection = null;
if (prevDirection === SORT_DIRECTION.ASC) {
nextDirection = SORT_DIRECTION.DESC;
}
if (prevDirection === SORT_DIRECTION.DESC) {
nextDirection = null;
}
if (prevDirection === null) {
nextDirection = SORT_DIRECTION.ASC;
}
if (title === 'name') {
this.setState({
nameDirection: nextDirection,
ageDirection: null,
});
return;
}
if (title === 'age') {
this.setState({
handleSort = (title: string, prevDirection: DirectionT) => {
let nextDirection = null;
if (prevDirection === SORT_DIRECTION.ASC) {
nextDirection = SORT_DIRECTION.DESC;
}
if (prevDirection === SORT_DIRECTION.DESC) {
nextDirection = null;
}
if (prevDirection === null) {
nextDirection = SORT_DIRECTION.ASC;
}
if (title === 'name') {
this.setState({
nameDirection: nextDirection,
ageDirection: null,
});
return;
}
handleSort = (title: string, prevDirection: DirectionT) => {
let nextDirection = null;
if (prevDirection === SORT_DIRECTION.ASC) {
nextDirection = SORT_DIRECTION.DESC;
}
if (prevDirection === SORT_DIRECTION.DESC) {
nextDirection = null;
}
if (prevDirection === null) {
nextDirection = SORT_DIRECTION.ASC;
}
if (title === 'name') {
this.setState({
nameDirection: nextDirection,
ageDirection: null,
});
return;
}
handleSort = (title: string, prevDirection: DirectionT) => {
let nextDirection = null;
if (prevDirection === SORT_DIRECTION.ASC) {
nextDirection = SORT_DIRECTION.DESC;
}
if (prevDirection === SORT_DIRECTION.DESC) {
nextDirection = null;
}
if (prevDirection === null) {
nextDirection = SORT_DIRECTION.ASC;
}
if (title === 'name') {
this.setState({
nameDirection: nextDirection,
ageDirection: null,
});
return;
}
if (title === 'age') {
this.setState({
if (this.state.nameDirection === SORT_DIRECTION.ASC) {
return sorted;
}
if (this.state.nameDirection === SORT_DIRECTION.DESC) {
return sorted.reverse();
}
}
if (this.state.ageDirection) {
const sorted = DATA.slice(0).sort((a, b) => a[1] - b[1]);
if (this.state.ageDirection === SORT_DIRECTION.ASC) {
return sorted;
}
if (this.state.ageDirection === SORT_DIRECTION.DESC) {
return sorted.reverse();
}
}
return DATA;
};