Skip to content

Commit 449e103

Browse files
kaganjdcatarak
authored andcommitted
Generate a two-word project name (#184)
* add name generator lib * update reducers * make initialState a function * update initialState function
1 parent d0f7326 commit 449e103

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

client/modules/IDE/reducers/files.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const defaultCSS =
3232
}
3333
`;
3434

35-
function initialState() {
35+
const initialState = () => {
3636
const a = objectID().toHexString();
3737
const b = objectID().toHexString();
3838
const c = objectID().toHexString();
@@ -70,7 +70,7 @@ function initialState() {
7070
fileType: 'file',
7171
children: []
7272
}];
73-
}
73+
};
7474

7575
function getAllDescendantIds(state, nodeId) {
7676
return state.find(file => file.id === nodeId).children

client/modules/IDE/reducers/project.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
import * as ActionTypes from '../../../constants';
2+
import generate from 'project-name-generator';
23

3-
const initialState = {
4-
name: 'Hello p5.js'
4+
const initialState = () => {
5+
const generatedString = generate({ words: 2 }).spaced;
6+
const generatedName = generatedString.charAt(0).toUpperCase() + generatedString.slice(1);
7+
return {
8+
name: generatedName
9+
};
510
};
611

7-
const project = (state = initialState, action) => {
12+
const project = (state, action) => {
13+
if (state === undefined) {
14+
state = initialState(); // eslint-disable-line
15+
}
816
switch (action.type) {
917
case ActionTypes.SET_PROJECT_NAME:
1018
return Object.assign({}, { ...state }, { name: action.name });
@@ -21,7 +29,7 @@ const project = (state = initialState, action) => {
2129
owner: action.owner
2230
};
2331
case ActionTypes.RESET_PROJECT:
24-
return initialState;
32+
return initialState();
2533
case ActionTypes.SHOW_EDIT_PROJECT_NAME:
2634
return Object.assign({}, state, { isEditingName: true });
2735
case ActionTypes.HIDE_EDIT_PROJECT_NAME:

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
"passport": "^0.3.2",
9595
"passport-github": "^1.1.0",
9696
"passport-local": "^1.0.0",
97+
"project-name-generator": "^2.1.3",
9798
"react": "^15.1.0",
9899
"react-dom": "^15.1.0",
99100
"react-inlinesvg": "^0.4.2",

0 commit comments

Comments
 (0)