static-cms/src/reducers/medias.js

24 lines
678 B
JavaScript
Raw Normal View History

2016-06-10 00:16:01 -03:00
import { Map } from 'immutable';
import { ADD_MEDIA } from '../actions/media';
import MediaProxy from '../valueObjects/MediaProxy';
const medias = (state = Map(), action) => {
switch (action.type) {
case ADD_MEDIA:
return state.set(action.payload.name, action.payload);
default:
return state;
}
};
export default medias;
export const getMedia = (state, filePath) => {
const fileName = filePath.substring(filePath.lastIndexOf('/') + 1);
if (state.has(fileName)) {
return new MediaProxy(fileName, window.URL.createObjectURL(state.get(fileName), {oneTimeOnly: true}));
} else {
return new MediaProxy(filePath, null, filePath, true);
}
};