import types from '../../types' const samplernnInitialState = { loading: true, progress: { i: 0, n: 0 }, error: null, folders: [], folder_id: 0, data: null, lossReport: null, } const samplernnReducer = (state = samplernnInitialState, action) => { // console.log(action.type) switch(action.type) { case types.samplernn.init: return { ...state, loading: false, data: action.data, } case types.socket.connect: return { ...state, } case types.task.task_begin: return { ...state, } case types.task.task_finish: return { ...state, } // so now the last thing is to figure out how to access things inside these datasets // and rebuild them if need be, considering this is SUPER awkward inside of redux. case types.folder.create: if (action.data.module === 'samplernn') { return { ...state, loading: false, data: { folders: state.data.folders.concat([action.data.id]), folderLookup: { ...state.data.folderLookup, [action.data.id]: action.data, } }, folder: { ...action.data, datasets: [], files: [], }, } } return state case types.file.create: if (action.data.module === 'samplernn') { console.log(action.data, state.folder) // const dataset = { // name, // input: [], // checkpoints: [], // output: [], // } let dataset, old_dataset, folder, old_folder const dataset_name = action.data.name.split('.')[0] if (dataset_name in state.data.datasets) { old_dataset = state.data.datasets[dataset_name] dataset = { ...old_dataset, input: action.data.generated ? old_dataset.input : [action.data.id].concat(old_dataset.input), output: !action.data.generated ? old_dataset.output : [action.data.id].concat(old_dataset.output), } } else { dataset = { name: dataset_name, date: action.data.created_at || action.data.date, input: action.data.generated ? [] : [action.data.id], checkpoints: [], output: !action.data.generated ? [] : [action.data.id], } } old_folder = state.data.folderLookup[action.data.folder_id] folder = { ...old_folder, files: old_folder.files.concat[action.data.id] } return { ...state, loading: false, data: { ...state.data, files: state.data.files.concat([action.data.id]), folderLookup: { ...state.data.folderLookup, [action.data.folder_id]: folder, }, fileLookup: { ...state.data.fileLookup, [action.data.id]: action.data, }, datasetLookup: { ...state.data.datasetLookup, [dataset_name]: dataset, }, } } } return state case types.file.update: if (action.data.module === 'samplernn') { return { ...state, loading: false, data: { ...state.data, fileLookup: { ...state.data.fileLookup, [action.data.id]: action.data, } } } } return state case types.folder.upload_complete: if (state.folder.id === action.folder) { return { ...state, loading: false, folder: { ...state.folder, input: [action.data].concat(state.folder.input), }, } } return state case types.socket.status: return samplernnSocket(state, action.data) case types.samplernn.set_folder: return { ...state, folder_id: action.folder_id, } case types.samplernn.load_loss: return { ...state, lossReport: action.lossReport, } case types.app.load_progress: return { ...state, progress: action.progress } default: return state } } const samplernnSocket = (state, action) => { console.log(action) switch (action.key) { case 'list_directory': return state default: return state } } export default samplernnReducer