p5.js-web-editor/client/modules/IDE/reducers/project.js
Cassie Tarakajian 18f646bde9
for , update babel to v7 ()
* for , upgrade babel to v7

* fix linting errors

* for , remove @babel/core from devDependencies (so it's only in dependencies) and change babel-loader config to use .babelrc

* for , changes to .babelrc to make  work

* for , include core-js modules in webpack config for IE support with babel/plugin-syntax-dynamic-import

* for , update babel and associated packages to LTS
2019-06-05 12:05:31 -04:00

60 lines
1.9 KiB
JavaScript

import friendlyWords from 'friendly-words';
import * as ActionTypes from '../../../constants';
const generateRandomName = () => {
const adj = friendlyWords.predicates[Math.floor(Math.random() * friendlyWords.predicates.length)];
const obj = friendlyWords.objects[Math.floor(Math.random() * friendlyWords.objects.length)];
return `${adj} ${obj}`;
};
const initialState = () => {
const generatedString = generateRandomName();
const generatedName = generatedString.charAt(0).toUpperCase() + generatedString.slice(1);
return {
name: generatedName,
updatedAt: '',
isSaving: false
};
};
const project = (state, action) => {
if (state === undefined) {
state = initialState(); // eslint-disable-line
}
switch (action.type) {
case ActionTypes.SET_PROJECT_NAME:
return Object.assign({}, { ...state }, { name: action.name });
case ActionTypes.NEW_PROJECT:
return {
id: action.project.id,
name: action.project.name,
updatedAt: action.project.updatedAt,
owner: action.owner,
isSaving: false
};
case ActionTypes.SET_PROJECT:
return {
id: action.project.id,
name: action.project.name,
updatedAt: action.project.updatedAt,
owner: action.owner,
isSaving: false
};
case ActionTypes.RESET_PROJECT:
return initialState();
case ActionTypes.SHOW_EDIT_PROJECT_NAME:
return Object.assign({}, state, { isEditingName: true });
case ActionTypes.HIDE_EDIT_PROJECT_NAME:
return Object.assign({}, state, { isEditingName: false });
case ActionTypes.SET_PROJECT_SAVED_TIME:
return Object.assign({}, state, { updatedAt: action.value });
case ActionTypes.START_SAVING_PROJECT:
return Object.assign({}, state, { isSaving: true });
case ActionTypes.END_SAVING_PROJECT:
return Object.assign({}, state, { isSaving: false });
default:
return state;
}
};
export default project;