diff options
Diffstat (limited to 'client/reducers/folders.js')
| -rw-r--r-- | client/reducers/folders.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/client/reducers/folders.js b/client/reducers/folders.js new file mode 100644 index 0000000..cbb5f5a --- /dev/null +++ b/client/reducers/folders.js @@ -0,0 +1,55 @@ +// import { addTask } from '../actions' +import client from '../client' + +const folders = (state = {}, action) => { + let file, folders, folder_id + + switch (action.type) { + case 'LOAD_FOLDERS': + return { + ...state, + folders: action.folders, + } + case 'LOAD_FILES': + if (! action.files.length) { + return state + } + folder_id = action.files[0].folder_id + console.log(state.folders) + folders = state.folders.map( (folder) => { + if (folder.id === folder_id) { + folder.files = action.files + } + return folder + }) + return { + ...state, + folders: folders, + } + case 'LOAD_OPEN_FOLDERS': + return { + ...state, + openFolders: action.folders, + } + case 'UPDATE_FILE': + file = action.file + folders = state.folders.map( (folder) => { + if (folder.id === file.folder_id && folder.files) { + folder.files = folder.files.map( f => f.id == file.id ? file : f ) + return Object.assign({}, folder) + } + else { + return folder + } + }) + + return { + ...state, + folders: folders + } + default: + return state + } +} + +export default folders |
