p5.js-web-editor/client/modules/IDE/reducers/sorting.js
siddhant b7df80a96c Add sorting to sketches #789 (#910)
* 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
2019-06-06 17:17:33 -04:00

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;