Skip to content

Commit ad6c826

Browse files
authored
Merge pull request #1401 from ajgreenb/instructions-ui-polish
Follow-up polish for Instructions editor UX
2 parents 310dba8 + 1a82612 commit ad6c826

File tree

10 files changed

+46
-18
lines changed

10 files changed

+46
-18
lines changed

src/actions/projects.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const updateProjectSource = createAction(
2121
export const updateProjectInstructions = createAction(
2222
'UPDATE_PROJECT_INSTRUCTIONS',
2323
(projectKey, newValue) => ({projectKey, newValue}),
24+
(_projectKey, _newValue, timestamp = Date.now()) => ({timestamp}),
2425
);
2526

2627
export const toggleLibrary = createAction(

src/components/InstructionsEditor.jsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ export default class InstructionsEditor extends React.Component {
99
bindAll(this, '_handleCancelEditing', '_handleSaveChanges', '_ref');
1010
}
1111

12+
componentDidMount() {
13+
if (!this.props.instructions) {
14+
this._editor.focus();
15+
}
16+
}
17+
1218
_handleCancelEditing() {
1319
this.props.onCancelEditing();
1420
}
@@ -43,6 +49,7 @@ export default class InstructionsEditor extends React.Component {
4349
<textarea
4450
className="instructions-editor__input"
4551
defaultValue={this.props.instructions}
52+
placeholder="Type here..."
4653
ref={this._ref}
4754
/>
4855
</div>

src/components/TopBar/LibraryPicker.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ const LibraryPicker = createMenu({
1313

1414
renderItems({enabledLibraries, onToggleLibrary}) {
1515
return map(libraries, (library, key) => {
16-
const isEnabled = enabledLibraries.includes(key);
16+
const isActive = enabledLibraries.includes(key);
1717

1818
return (
1919
<MenuItem
20-
isEnabled={isEnabled}
20+
isActive={isActive}
2121
key={key}
2222
onClick={partial(onToggleLibrary, key)}
2323
>
24-
<span className={classnames('u__icon', {u__invisible: !isEnabled})}>
24+
<span className={classnames('u__icon', {u__invisible: !isActive})}>
2525
&#xf00c;{' '}
2626
</span>
2727
{library.name}

src/components/TopBar/ProjectPicker.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const ProjectPicker = createMenu({
2020
renderItems({currentProjectKey, projectKeys, onChangeCurrentProject}) {
2121
return map(projectKeys, projectKey => (
2222
<MenuItem
23-
isEnabled={projectKey === currentProjectKey}
23+
isActive={projectKey === currentProjectKey}
2424
key={projectKey}
2525
onClick={partial(onChangeCurrentProject, projectKey)}
2626
>

src/components/TopBar/createMenu.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import React from 'react';
1212
import {closeTopBarMenu, toggleTopBarMenu} from '../../actions';
1313
import {getOpenTopBarMenu} from '../../selectors';
1414

15-
export function MenuItem({children, isDisabled, isEnabled, onClick}) {
15+
export function MenuItem({children, isActive, isDisabled, onClick}) {
1616
return (
1717
<div
1818
className={classnames('top-bar__menu-item', {
19-
'top-bar__menu-item_active': isEnabled,
19+
'top-bar__menu-item_active': isActive,
2020
'top-bar__menu-item_disabled': isDisabled,
2121
})}
2222
onClick={isDisabled ? noop : onClick}
@@ -28,14 +28,14 @@ export function MenuItem({children, isDisabled, isEnabled, onClick}) {
2828

2929
MenuItem.propTypes = {
3030
children: PropTypes.node.isRequired,
31+
isActive: PropTypes.bool,
3132
isDisabled: PropTypes.bool,
32-
isEnabled: PropTypes.bool,
3333
onClick: PropTypes.func.isRequired,
3434
};
3535

3636
MenuItem.defaultProps = {
37+
isActive: false,
3738
isDisabled: false,
38-
isEnabled: false,
3939
};
4040

4141
export default function createMenu({

src/css/application.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ body {
376376
height: 100%;
377377
padding: 0.5rem;
378378
box-sizing: border-box;
379+
font-family: 'Inconsolata';
379380
font-size: 1rem;
380381
border: 0;
381382
outline: 0;

src/reducers/projects.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ export default function reduceProjects(stateIn, action) {
119119
return state.setIn(
120120
[action.payload.projectKey, 'instructions'],
121121
action.payload.newValue,
122+
).setIn(
123+
[action.payload.projectKey, 'updatedAt'],
124+
action.meta.timestamp,
122125
);
123126

124127
case 'PROJECT_CREATED':

src/sagas/projects.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ export default function* () {
110110
takeEvery('APPLICATION_LOADED', applicationLoaded),
111111
takeEvery('CREATE_PROJECT', createProject),
112112
takeEvery('CHANGE_CURRENT_PROJECT', changeCurrentProject),
113-
throttle(500, 'UPDATE_PROJECT_SOURCE', updateProjectSource),
113+
throttle(500, [
114+
'UPDATE_PROJECT_SOURCE',
115+
'UPDATE_PROJECT_INSTRUCTIONS',
116+
], updateProjectSource),
114117
takeEvery('USER_AUTHENTICATED', userAuthenticated),
115118
takeEvery('TOGGLE_LIBRARY', toggleLibrary),
116119
]);

test/unit/reducers/projects.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,16 @@ test('updateProjectSource', reducerTest(
6666
),
6767
));
6868

69-
tap(initProjects({1: false}), projects =>
70-
test('updateProjectInstructions', reducerTest(
71-
reducer,
72-
projects,
73-
partial(updateProjectInstructions, '1', '# Instructions\n\nHello.'),
74-
projects.update('1', projectIn =>
75-
projectIn.set('instructions', '# Instructions\n\nHello.'),
69+
test('updateProjectInstructions', reducerTest(
70+
reducer,
71+
initProjects({[projectKey]: false}),
72+
partial(updateProjectInstructions, projectKey, '# Instructions', now),
73+
initProjects({[projectKey]: true}).
74+
update(
75+
projectKey,
76+
editedProject => editedProject.set('instructions', '# Instructions'),
7677
),
77-
)),
78-
);
78+
));
7979

8080
test('changeCurrentProject', (t) => {
8181
t.test('from modified to pristine', reducerTest(

test/unit/sagas/projects.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
gistNotFound,
1717
projectsLoaded,
1818
toggleLibrary,
19+
updateProjectInstructions,
1920
updateProjectSource,
2021
} from '../../../src/actions/projects';
2122
import {
@@ -230,6 +231,18 @@ test('updateProjectSource', (assert) => {
230231
assert.end();
231232
});
232233

234+
test('updateProjectInstructions', (assert) => {
235+
const scenario = new Scenario();
236+
testSaga(
237+
updateProjectSourceSaga,
238+
updateProjectInstructions(scenario.projectKey, '# Instructions'),
239+
).
240+
next().select().
241+
next(scenario.state).call(saveCurrentProject, scenario.state).
242+
next().isDone();
243+
assert.end();
244+
});
245+
233246
test('toggleLibrary', (assert) => {
234247
const scenario = new Scenario();
235248
testSaga(

0 commit comments

Comments
 (0)