2019-04-11 20:25:37 +00:00
|
|
|
import friendlyWords from 'friendly-words';
|
2017-02-22 19:29:35 +00:00
|
|
|
import * as ActionTypes from '../../../constants';
|
2016-06-16 20:07:38 +00:00
|
|
|
|
2019-04-11 20:25:37 +00:00
|
|
|
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}`;
|
|
|
|
};
|
|
|
|
|
2016-11-16 21:29:17 +00:00
|
|
|
const initialState = () => {
|
2019-04-11 20:25:37 +00:00
|
|
|
const generatedString = generateRandomName();
|
2016-11-16 21:29:17 +00:00
|
|
|
const generatedName = generatedString.charAt(0).toUpperCase() + generatedString.slice(1);
|
|
|
|
return {
|
2017-03-30 16:36:26 +00:00
|
|
|
name: generatedName,
|
2019-04-17 18:08:33 +00:00
|
|
|
updatedAt: '',
|
|
|
|
isSaving: false
|
2016-11-16 21:29:17 +00:00
|
|
|
};
|
2016-06-23 22:29:55 +00:00
|
|
|
};
|
2016-06-16 20:07:38 +00:00
|
|
|
|
2016-11-16 21:29:17 +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 {
|
2017-01-24 20:29:25 +00:00
|
|
|
id: action.project.id,
|
|
|
|
name: action.project.name,
|
|
|
|
updatedAt: action.project.updatedAt,
|
2019-04-17 18:08:33 +00:00
|
|
|
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,
|
2017-01-24 20:29:25 +00:00
|
|
|
updatedAt: action.project.updatedAt,
|
2019-04-17 18:08:33 +00:00
|
|
|
owner: action.owner,
|
|
|
|
isSaving: false
|
2016-06-23 22:29:55 +00:00
|
|
|
};
|
2016-08-12 16:45:26 +00:00
|
|
|
case ActionTypes.RESET_PROJECT:
|
2016-11-16 21:29:17 +00:00
|
|
|
return initialState();
|
2016-08-15 16:42:13 +00:00
|
|
|
case ActionTypes.SHOW_EDIT_PROJECT_NAME:
|
|
|
|
return Object.assign({}, state, { isEditingName: true });
|
|
|
|
case ActionTypes.HIDE_EDIT_PROJECT_NAME:
|
|
|
|
return Object.assign({}, state, { isEditingName: false });
|
2017-03-02 19:38:29 +00:00
|
|
|
case ActionTypes.SET_PROJECT_SAVED_TIME:
|
|
|
|
return Object.assign({}, state, { updatedAt: action.value });
|
2019-04-17 18:08:33 +00:00
|
|
|
case ActionTypes.START_SAVING_PROJECT:
|
|
|
|
return Object.assign({}, state, { isSaving: true });
|
2019-06-05 16:05:31 +00:00
|
|
|
case ActionTypes.END_SAVING_PROJECT:
|
2019-04-17 18:08:33 +00:00
|
|
|
return Object.assign({}, state, { isSaving: false });
|
2016-06-23 22:29:55 +00:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|
2016-06-16 20:07:38 +00:00
|
|
|
|
2016-06-23 22:29:55 +00:00
|
|
|
export default project;
|