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.js25
1 files changed, 22 insertions, 3 deletions
diff --git a/client/reducers/folders.js b/client/reducers/folders.js
index a69df74..bec4ad3 100644
--- a/client/reducers/folders.js
+++ b/client/reducers/folders.js
@@ -2,7 +2,7 @@
import client from '../client'
const folders = (state = {}, action) => {
- let file, files, folders, folder, openFolders, folder_id
+ let file, files, folders, folder, openFolders, folder_id, filesAreLoaded
console.log(action)
switch (action.type) {
case 'LOAD_FOLDERS':
@@ -24,7 +24,14 @@ const folders = (state = {}, action) => {
})
return {
...state,
- folders: folders,
+ folders
+ }
+
+ case 'ADD_FOLDER':
+ folders = [ action.folder ].concat(state.folders)
+ return {
+ ...state,
+ folders
}
case 'LOAD_OPEN_FOLDERS':
@@ -36,10 +43,22 @@ const folders = (state = {}, action) => {
case 'OPEN_FOLDER':
openFolders = state.openFolders
folder = action.folder
+ folder_id = folder.id
if (openFolders.indexOf(folder.id) === -1) {
openFolders = openFolders.concat(folder.id)
localStorage['openFolders'] = JSON.stringify(openFolders)
}
+ filesAreLoaded = state.folders.some( (folder) => {
+ if (folder.id === folder_id && folder.files) {
+ return true
+ }
+ return false
+ })
+ if (! filesAreLoaded) {
+ client.file.index({ folder_id }).then( (files) => {
+ action.cb && action.cb(files)
+ })
+ }
return {
...state,
openFolders,
@@ -57,7 +76,7 @@ const folders = (state = {}, action) => {
case 'ADD_FILES':
files = action.files
- folder_id = Number(files[0].folder_id)
+ folder_id = Number(files[0] && files[0].folder_id)
folders = state.folders.map( (folder) => {
if (folder.id === folder_id) {
folder.files = ( folder.files || [] ).concat(files)