2016-11-16 22:29:17 +01:00
|
|
|
import generate from 'project-name-generator';
|
2017-02-22 20:29:35 +01:00
|
|
|
import * as ActionTypes from '../../../constants';
|
2017-04-20 20:05:15 +02:00
|
|
|
import isSecurePage from '../../../utils/isSecurePage';
|
2016-06-16 22:07:38 +02:00
|
|
|
|
2016-11-16 22:29:17 +01:00
|
|
|
const initialState = () => {
|
|
|
|
const generatedString = generate({ words: 2 }).spaced;
|
|
|
|
const generatedName = generatedString.charAt(0).toUpperCase() + generatedString.slice(1);
|
|
|
|
return {
|
2017-03-30 18:36:26 +02:00
|
|
|
name: generatedName,
|
2017-04-20 20:05:15 +02:00
|
|
|
serveSecure: isSecurePage(),
|
2017-07-17 23:34:11 +02:00
|
|
|
updatedAt: ''
|
2016-11-16 22:29:17 +01:00
|
|
|
};
|
2016-06-24 00:29:55 +02:00
|
|
|
};
|
2016-06-16 22:07:38 +02:00
|
|
|
|
2016-11-16 22:29:17 +01:00
|
|
|
const project = (state, action) => {
|
|
|
|
if (state === undefined) {
|
|
|
|
state = initialState(); // eslint-disable-line
|
|
|
|
}
|
2016-06-24 00:29:55 +02:00
|
|
|
switch (action.type) {
|
2017-05-03 17:46:12 +02:00
|
|
|
case ActionTypes.SET_SERVE_SECURE:
|
|
|
|
return Object.assign({}, { ...state }, { serveSecure: action.serveSecure });
|
2016-06-24 00:29:55 +02:00
|
|
|
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 {
|
2017-01-24 21:29:25 +01:00
|
|
|
id: action.project.id,
|
|
|
|
name: action.project.name,
|
|
|
|
updatedAt: action.project.updatedAt,
|
2017-05-03 17:46:12 +02:00
|
|
|
serveSecure: action.project.serveSecure,
|
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,
|
2017-01-24 21:29:25 +01:00
|
|
|
updatedAt: action.project.updatedAt,
|
2017-05-03 17:46:12 +02:00
|
|
|
serveSecure: action.project.serveSecure,
|
2016-07-15 17:54:47 +02:00
|
|
|
owner: action.owner
|
2016-06-24 00:29:55 +02:00
|
|
|
};
|
2016-08-12 18:45:26 +02:00
|
|
|
case ActionTypes.RESET_PROJECT:
|
2016-11-16 22:29:17 +01:00
|
|
|
return initialState();
|
2016-08-15 18:42:13 +02: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 20:38:29 +01:00
|
|
|
case ActionTypes.SET_PROJECT_SAVED_TIME:
|
|
|
|
return Object.assign({}, state, { updatedAt: action.value });
|
2016-06-24 00:29:55 +02:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|
2016-06-16 22:07:38 +02:00
|
|
|
|
2016-06-24 00:29:55 +02:00
|
|
|
export default project;
|