summaryrefslogtreecommitdiff
path: root/client/reducers/folders.js
diff options
context:
space:
mode:
Diffstat (limited to 'client/reducers/folders.js')
-rw-r--r--client/reducers/folders.js64
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) => {