p5.js-web-editor/client/modules/IDE/reducers/project.js

45 lines
1.3 KiB
JavaScript
Raw Normal View History

2016-06-22 21:58:23 +02:00
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
};
2016-06-24 00:29:55 +02:00
};
const project = (state, action) => {
if (state === undefined) {
state = initialState(); // eslint-disable-line
}
2016-06-24 00:29:55 +02:00
switch (action.type) {
case ActionTypes.SET_PROJECT_NAME:
2016-07-15 17:54:47 +02:00
return Object.assign({}, { ...state }, { name: action.name });
2016-06-24 00:29:55 +02:00
case ActionTypes.NEW_PROJECT:
return {
id: action.project.id,
name: action.project.name,
updatedAt: action.project.updatedAt,
2016-07-15 17:54:47 +02:00
owner: action.owner
2016-06-24 00:29:55 +02:00
};
case ActionTypes.SET_PROJECT:
return {
id: action.project.id,
2016-07-15 17:54:47 +02:00
name: action.project.name,
updatedAt: action.project.updatedAt,
2016-07-15 17:54:47 +02:00
owner: action.owner
2016-06-24 00:29:55 +02:00
};
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 });
2016-06-24 00:29:55 +02:00
default:
return state;
}
};
2016-06-24 00:29:55 +02:00
export default project;