8caeb0d439
* reselect added * Added Reselect Sorting * Refactor App * added svgs * Refactor * Fixed Issues * re: #789, update sorting styling, create sorting actions and reducers, add sort by sketch name * re #789, change names of svg icons * re: #789, use orderBy instead of sortBy, fix styling jumps
29 lines
919 B
JavaScript
29 lines
919 B
JavaScript
import * as ActionTypes from '../../../constants';
|
|
import { DIRECTION } from '../actions/sorting';
|
|
|
|
const initialState = {
|
|
field: 'createdAt',
|
|
direction: DIRECTION.DESC
|
|
};
|
|
|
|
const sorting = (state = initialState, action) => {
|
|
switch (action.type) {
|
|
case ActionTypes.TOGGLE_DIRECTION:
|
|
if (action.field && action.field !== state.field) {
|
|
if (action.field === 'name') {
|
|
return { ...state, field: action.field, direction: DIRECTION.ASC };
|
|
}
|
|
return { ...state, field: action.field, direction: DIRECTION.DESC };
|
|
}
|
|
if (state.direction === DIRECTION.ASC) {
|
|
return { ...state, direction: DIRECTION.DESC };
|
|
}
|
|
return { ...state, direction: DIRECTION.ASC };
|
|
case ActionTypes.SET_SORTING:
|
|
return { ...state, field: action.payload.field, direction: action.payload.direction };
|
|
default:
|
|
return state;
|
|
}
|
|
};
|
|
|
|
export default sorting;
|