diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2017-07-07 21:40:15 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2017-07-07 21:40:15 +0200 |
| commit | 11a70bc347587219b2ec7b63cf4a6ff69bb4199b (patch) | |
| tree | 855a25211d35ae1dc1533200f90381ec7702896b /client/reducers | |
| parent | 84774bfb162eda1e09495a6c55fb86393deedfe8 (diff) | |
upload files and they show up, then process
Diffstat (limited to 'client/reducers')
| -rw-r--r-- | client/reducers/folders.js | 64 |
1 files changed, 62 insertions, 2 deletions
diff --git a/client/reducers/folders.js b/client/reducers/folders.js index 594abf9..d6bdd46 100644 --- a/client/reducers/folders.js +++ b/client/reducers/folders.js @@ -2,14 +2,15 @@ import client from '../client' const folders = (state = {}, action) => { - let file, folders, folder_id - + let file, files, folders, folder, openFolders, folder_id + console.log(action) switch (action.type) { case 'LOAD_FOLDERS': return { ...state, folders: action.folders, } + case 'LOAD_FILES': if (! action.files.length) { return state @@ -25,11 +26,70 @@ const folders = (state = {}, action) => { ...state, folders: folders, } + case 'LOAD_OPEN_FOLDERS': return { ...state, openFolders: action.folders, } + + case 'OPEN_FOLDER': + openFolders = state.openFolders + folder = action.folder + if (openFolders.indexOf(folder.id) === -1) { + openFolders = openFolders.concat(folder.id) + localStorage['openFolders'] = JSON.stringify(openFolders) + } + return { + ...state, + openFolders, + } + + case 'CLOSE_FOLDER': + folder = action.folder + openFolders = state.openFolders.filter( folder_id => folder_id !== folder.id ) + localStorage['openFolders'] = JSON.stringify(openFolders) + + return { + ...state, + openFolders, + } + + case 'ADD_FILES': + files = action.files + folder_id = Number(files[0].folder_id) + folders = state.folders.map( (folder) => { + if (folder.id === folder_id) { + folder.files = ( folder.files || [] ).concat(files) + return Object.assign({}, folder) + } + else { + return folder + } + }) + + return { + ...state, + folders + } + + case 'ADD_FILE': + file = action.file + folders = state.folders.map( (folder) => { + if (folder.id === file.folder_id) { + folder.files = folder.files || [] + folder.files.push(file) + return Object.assign({}, folder) + } + else { + return folder + } + }) + + return { + ...state, + folders + } case 'UPDATE_FILE': file = action.file folders = state.folders.map( (folder) => { |
