p5.js-web-editor/client/modules/IDE/reducers/project.js
Jen Kagan 449e103fc6 Generate a two-word project name (#184)
* add name generator lib

* update reducers

* make initialState a function

* update initialState function
2016-11-16 16:29:17 -05:00

42 lines
1.2 KiB
JavaScript

import * as ActionTypes from '../../../constants';
import generate from 'project-name-generator';
const initialState = () => {
const generatedString = generate({ words: 2 }).spaced;
const generatedName = generatedString.charAt(0).toUpperCase() + generatedString.slice(1);
return {
name: generatedName
};
};
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.id,
name: action.name,
owner: action.owner
};
case ActionTypes.SET_PROJECT:
return {
id: action.project.id,
name: action.project.name,
owner: action.owner
};
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 });
default:
return state;
}
};
export default project;