blob: 594abf91e2bf9e0c0bb444bf70ce1900d6f49c27 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
// 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
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
|