static-cms/src/reducers/medias.js

30 lines
725 B
JavaScript
Raw Normal View History

2016-06-10 00:16:01 -03:00
import { Map } from 'immutable';
2016-06-10 14:01:14 -03:00
import { ADD_MEDIA, REMOVE_MEDIA } from '../actions/media';
2016-06-10 00:16:01 -03:00
import MediaProxy from '../valueObjects/MediaProxy';
const medias = (state = Map(), action) => {
switch (action.type) {
case ADD_MEDIA:
return state.set(action.payload.public_path, action.payload);
2016-06-10 14:01:14 -03:00
case REMOVE_MEDIA:
return state.delete(action.payload);
2016-06-10 00:16:01 -03:00
default:
return state;
}
};
export default medias;
export const getMedia = (publicFolder, state, path) => {
2016-07-19 17:11:22 -03:00
if (state.has(path)) {
return state.get(path);
2016-06-10 00:16:01 -03:00
}
let localPath = path;
if (path && path.indexOf('/') === -1) {
localPath = `/${ publicFolder }/${ localPath }`;
}
return new MediaProxy(localPath, null, true);
2016-06-10 00:16:01 -03:00
};