From 449e103fc60fe6c1586bcef4f12f710add6d4899 Mon Sep 17 00:00:00 2001 From: Jen Kagan Date: Wed, 16 Nov 2016 16:29:17 -0500 Subject: [PATCH] Generate a two-word project name (#184) * add name generator lib * update reducers * make initialState a function * update initialState function --- client/modules/IDE/reducers/files.js | 4 ++-- client/modules/IDE/reducers/project.js | 16 ++++++++++++---- package.json | 1 + 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/client/modules/IDE/reducers/files.js b/client/modules/IDE/reducers/files.js index f07727e0..8c4c057b 100644 --- a/client/modules/IDE/reducers/files.js +++ b/client/modules/IDE/reducers/files.js @@ -32,7 +32,7 @@ const defaultCSS = } `; -function initialState() { +const initialState = () => { const a = objectID().toHexString(); const b = objectID().toHexString(); const c = objectID().toHexString(); @@ -70,7 +70,7 @@ function initialState() { fileType: 'file', children: [] }]; -} +}; function getAllDescendantIds(state, nodeId) { return state.find(file => file.id === nodeId).children diff --git a/client/modules/IDE/reducers/project.js b/client/modules/IDE/reducers/project.js index efca305b..7d4df05e 100644 --- a/client/modules/IDE/reducers/project.js +++ b/client/modules/IDE/reducers/project.js @@ -1,10 +1,18 @@ import * as ActionTypes from '../../../constants'; +import generate from 'project-name-generator'; -const initialState = { - name: 'Hello p5.js' +const initialState = () => { + const generatedString = generate({ words: 2 }).spaced; + const generatedName = generatedString.charAt(0).toUpperCase() + generatedString.slice(1); + return { + name: generatedName + }; }; -const project = (state = initialState, action) => { +const project = (state, action) => { + if (state === undefined) { + state = initialState(); // eslint-disable-line + } switch (action.type) { case ActionTypes.SET_PROJECT_NAME: return Object.assign({}, { ...state }, { name: action.name }); @@ -21,7 +29,7 @@ const project = (state = initialState, action) => { owner: action.owner }; case ActionTypes.RESET_PROJECT: - return initialState; + return initialState(); case ActionTypes.SHOW_EDIT_PROJECT_NAME: return Object.assign({}, state, { isEditingName: true }); case ActionTypes.HIDE_EDIT_PROJECT_NAME: diff --git a/package.json b/package.json index 109826bb..61e9c721 100644 --- a/package.json +++ b/package.json @@ -94,6 +94,7 @@ "passport": "^0.3.2", "passport-github": "^1.1.0", "passport-local": "^1.0.0", + "project-name-generator": "^2.1.3", "react": "^15.1.0", "react-dom": "^15.1.0", "react-inlinesvg": "^0.4.2",