summaryrefslogtreecommitdiff
path: root/client/reducers
diff options
context:
space:
mode:
Diffstat (limited to 'client/reducers')
-rw-r--r--client/reducers/folders.js55
-rw-r--r--client/reducers/index.js8
-rw-r--r--client/reducers/tasks.js13
3 files changed, 74 insertions, 2 deletions
diff --git a/client/reducers/folders.js b/client/reducers/folders.js
new file mode 100644
index 0000000..cbb5f5a
--- /dev/null
+++ b/client/reducers/folders.js
@@ -0,0 +1,55 @@
+// 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
+ console.log(state.folders)
+ 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
diff --git a/client/reducers/index.js b/client/reducers/index.js
index 0dee19c..8fa287b 100644
--- a/client/reducers/index.js
+++ b/client/reducers/index.js
@@ -1,11 +1,15 @@
import { combineReducers } from 'redux'
-import currentTask from './currentTask'
import audioPlayer from './audioPlayer'
+import currentTask from './currentTask'
+import tasks from './tasks'
+import folders from './folders'
const cortexApp = combineReducers({
- currentTask,
audioPlayer,
+ currentTask,
+ tasks,
+ folders,
})
export default cortexApp
diff --git a/client/reducers/tasks.js b/client/reducers/tasks.js
new file mode 100644
index 0000000..d6ef8e1
--- /dev/null
+++ b/client/reducers/tasks.js
@@ -0,0 +1,13 @@
+// import { addTask } from '../actions'
+import client from '../client'
+
+const tasks = (state = {}, action) => {
+ switch (action.type) {
+ case 'LOAD_TASKS':
+ return action.tasks
+ default:
+ return state
+ }
+}
+
+export default tasks \ No newline at end of file