diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2017-07-07 21:18:33 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2017-07-07 21:18:33 +0200 |
| commit | f8b61281be84a6e4e7a44be5109e688a7c56c671 (patch) | |
| tree | 43797c6b6cfa5c0f89c020f8c89e0da10f791a55 /client/reducers/folders.js | |
| parent | 3d3a7b80d34c100846c8ae130b424b63ba3c0784 (diff) | |
refactor files so list updates while processing
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 |
