p5.js-web-editor/client/modules/IDE/reducers/project.js
Andrew Nicolaou ae668f681e HTTPS UI switch (#335)
* Checkbox to toggle project's serveSecure flag

This doesn't yet persist or reload the page.

* Help button that shows modal to explain feature

* Extracts protocol redirection to helper

* Returns promise from saveProject() action to allow chaining

* Setting serveSecure flag on project redirects after saving project

* Set serveSecure on Project model in API and client

* Redirect to correct protocol when project is loaded
2017-05-03 11:46:12 -04:00

52 lines
1.7 KiB
JavaScript

import generate from 'project-name-generator';
import * as ActionTypes from '../../../constants';
import isSecurePage from '../../../utils/isSecurePage';
const initialState = () => {
const generatedString = generate({ words: 2 }).spaced;
const generatedName = generatedString.charAt(0).toUpperCase() + generatedString.slice(1);
return {
name: generatedName,
serveSecure: isSecurePage(),
};
};
const project = (state, action) => {
if (state === undefined) {
state = initialState(); // eslint-disable-line
}
switch (action.type) {
case ActionTypes.SET_SERVE_SECURE:
return Object.assign({}, { ...state }, { serveSecure: action.serveSecure });
case ActionTypes.SET_PROJECT_NAME:
return Object.assign({}, { ...state }, { name: action.name });
case ActionTypes.NEW_PROJECT:
return {
id: action.project.id,
name: action.project.name,
updatedAt: action.project.updatedAt,
serveSecure: action.project.serveSecure,
owner: action.owner
};
case ActionTypes.SET_PROJECT:
return {
id: action.project.id,
name: action.project.name,
updatedAt: action.project.updatedAt,
serveSecure: action.project.serveSecure,
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 });
case ActionTypes.SET_PROJECT_SAVED_TIME:
return Object.assign({}, state, { updatedAt: action.value });
default:
return state;
}
};
export default project;