Refactor on upload media data fow

This commit is contained in:
Cássio Zen
2016-06-10 14:01:14 -03:00
parent 1ba98fdb5a
commit 1700f98e4e
8 changed files with 47 additions and 40 deletions

View File

@ -1,6 +1,6 @@
import { Map, List } from 'immutable';
import { DRAFT_CREATE, DRAFT_DISCARD, DRAFT_CHANGE } from '../actions/entries';
import { ADD_MEDIA } from '../actions/media';
import { ADD_MEDIA, REMOVE_MEDIA } from '../actions/media';
const initialState = Map({entry: Map(), mediaFiles: List()});
@ -22,7 +22,9 @@ const entryDraft = (state = Map(), action) => {
return state.set('entry', action.payload);
case ADD_MEDIA:
return state.update('mediaFiles', (list) => list.push(action.payload.name));
return state.update('mediaFiles', (list) => list.push(action.payload.uri));
case REMOVE_MEDIA:
return state.update('mediaFiles', (list) => list.filterNot((uri) => uri === action.payload));
default:
return state;

View File

@ -1,11 +1,13 @@
import { Map } from 'immutable';
import { ADD_MEDIA } from '../actions/media';
import { ADD_MEDIA, REMOVE_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);
return state.set(action.payload.uri, action.payload);
case REMOVE_MEDIA:
return state.delete(action.payload);
default:
return state;
}
@ -13,11 +15,10 @@ const medias = (state = Map(), action) => {
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}));
export const getMedia = (state, uri) => {
if (state.has(uri)) {
return state.get(uri);
} else {
return new MediaProxy(filePath, null, filePath, true);
return new MediaProxy(uri, null, true);
}
};