parent
8f45fe0afe
commit
90d9741056
@ -0,0 +1,11 @@
|
|||||||
|
import createFetchHandler from './Creators/createFetchHandler';
|
||||||
|
import * as types from './actionTypes';
|
||||||
|
|
||||||
|
const section = 'tracks';
|
||||||
|
|
||||||
|
const trackActionHandlers = {
|
||||||
|
[types.FETCH_TRACKS]: createFetchHandler(section, '/track')
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
export default trackActionHandlers;
|
@ -0,0 +1,8 @@
|
|||||||
|
import { createAction } from 'redux-actions';
|
||||||
|
import * as types from './actionTypes';
|
||||||
|
import trackActionHandlers from './trackActionHandlers';
|
||||||
|
|
||||||
|
export const fetchTracks = trackActionHandlers[types.FETCH_TRACKS];
|
||||||
|
export const setTracksSort = createAction(types.SET_TRACKS_SORT);
|
||||||
|
export const setTracksTableOption = createAction(types.SET_TRACKS_TABLE_OPTION);
|
||||||
|
export const clearTracks = createAction(types.CLEAR_TRACKS);
|
@ -0,0 +1,70 @@
|
|||||||
|
import { handleActions } from 'redux-actions';
|
||||||
|
import * as types from 'Store/Actions/actionTypes';
|
||||||
|
import { sortDirections } from 'Helpers/Props';
|
||||||
|
import createSetReducer from './Creators/createSetReducer';
|
||||||
|
import createSetTableOptionReducer from './Creators/createSetTableOptionReducer';
|
||||||
|
import createUpdateReducer from './Creators/createUpdateReducer';
|
||||||
|
import createUpdateItemReducer from './Creators/createUpdateItemReducer';
|
||||||
|
import createSetClientSideCollectionSortReducer from './Creators/createSetClientSideCollectionSortReducer';
|
||||||
|
|
||||||
|
export const defaultState = {
|
||||||
|
isFetching: false,
|
||||||
|
isPopulated: false,
|
||||||
|
error: null,
|
||||||
|
sortKey: 'trackNumber',
|
||||||
|
sortDirection: sortDirections.DESCENDING,
|
||||||
|
items: [],
|
||||||
|
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
name: 'trackNumber',
|
||||||
|
label: 'Track Number',
|
||||||
|
isVisible: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'title',
|
||||||
|
label: 'Title',
|
||||||
|
isVisible: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'duration',
|
||||||
|
label: 'Duration',
|
||||||
|
isVisible: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'actions',
|
||||||
|
columnLabel: 'Actions',
|
||||||
|
isVisible: true,
|
||||||
|
isModifiable: false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
export const persistState = [
|
||||||
|
'tracks.columns'
|
||||||
|
];
|
||||||
|
|
||||||
|
const reducerSection = 'tracks';
|
||||||
|
|
||||||
|
const trackReducers = handleActions({
|
||||||
|
|
||||||
|
[types.SET]: createSetReducer(reducerSection),
|
||||||
|
[types.UPDATE]: createUpdateReducer(reducerSection),
|
||||||
|
[types.UPDATE_ITEM]: createUpdateItemReducer(reducerSection),
|
||||||
|
|
||||||
|
[types.SET_TRACKS_TABLE_OPTION]: createSetTableOptionReducer(reducerSection),
|
||||||
|
|
||||||
|
[types.CLEAR_TRACKS]: (state) => {
|
||||||
|
return Object.assign({}, state, {
|
||||||
|
isFetching: false,
|
||||||
|
isPopulated: false,
|
||||||
|
error: null,
|
||||||
|
items: []
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
[types.SET_TRACKS_SORT]: createSetClientSideCollectionSortReducer(reducerSection)
|
||||||
|
|
||||||
|
}, defaultState);
|
||||||
|
|
||||||
|
export default trackReducers;
|
@ -0,0 +1,14 @@
|
|||||||
|
import _ from 'lodash';
|
||||||
|
import { createSelector } from 'reselect';
|
||||||
|
|
||||||
|
function createTrackSelector() {
|
||||||
|
return createSelector(
|
||||||
|
(state, { trackId }) => trackId,
|
||||||
|
(state) => state.tracks,
|
||||||
|
(trackId, tracks) => {
|
||||||
|
return _.find(tracks.items, { id: trackId });
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default createTrackSelector;
|
Loading…
Reference in new issue