From 11a70bc347587219b2ec7b63cf4a6ff69bb4199b Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 7 Jul 2017 21:40:15 +0200 Subject: upload files and they show up, then process --- client/reducers/folders.js | 64 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) (limited to 'client/reducers') 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) => { -- cgit v1.2.3-70-g09d2