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

55 lines
1.7 KiB
JavaScript
Raw Normal View History

import * as ActionTypes from '../../../constants';
2019-07-09 16:24:09 +00:00
import { generateProjectName } from '../../../utils/generateRandomName';
2019-04-11 20:25:37 +00:00
const initialState = () => {
2019-07-09 16:24:09 +00:00
const generatedString = generateProjectName();
const generatedName = generatedString.charAt(0).toUpperCase() + generatedString.slice(1);
return {
name: generatedName,
updatedAt: '',
isSaving: false
};
2016-06-23 22:29:55 +00:00
};
const project = (state, action) => {
if (state === undefined) {
state = initialState(); // eslint-disable-line
}
2016-06-23 22:29:55 +00:00
switch (action.type) {
case ActionTypes.SET_PROJECT_NAME:
2016-07-15 15:54:47 +00:00
return Object.assign({}, { ...state }, { name: action.name });
2016-06-23 22:29:55 +00:00
case ActionTypes.NEW_PROJECT:
return {
id: action.project.id,
name: action.project.name,
updatedAt: action.project.updatedAt,
owner: action.owner,
isSaving: false
2016-06-23 22:29:55 +00:00
};
case ActionTypes.SET_PROJECT:
return {
id: action.project.id,
2016-07-15 15:54:47 +00:00
name: action.project.name,
updatedAt: action.project.updatedAt,
owner: action.owner,
isSaving: false
2016-06-23 22:29:55 +00: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 });
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 });
2016-06-23 22:29:55 +00:00
default:
return state;
}
};
2016-06-23 22:29:55 +00:00
export default project;