Skip to content

Commit 239d811

Browse files
author
Mat Brown
committed
Instructions component
* Change `<Dashboard>` to `<Instructions>` * Component is visible by default if instructions are present * Can be hidden by clicking instructions bar; uses same mechanism as minimizing editors etc. * Neither bar nor instructions appear at all if there are no instructions in the project
1 parent 2cc137f commit 239d811

18 files changed

Lines changed: 128 additions & 292 deletions

File tree

src/actions/index.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
toggleLibrary,
1717
hideComponent,
1818
unhideComponent,
19+
toggleComponent,
1920
updateProjectSource,
2021
} from './projects';
2122

@@ -44,10 +45,6 @@ import {
4445
userLoggedOut,
4546
} from './user';
4647

47-
function toggleDashboard() {
48-
return {type: 'DASHBOARD_TOGGLED'};
49-
}
50-
5148
export {
5249
createProject,
5350
createSnapshot,
@@ -59,7 +56,7 @@ export {
5956
addRuntimeError,
6057
hideComponent,
6158
unhideComponent,
62-
toggleDashboard,
59+
toggleComponent,
6360
focusLine,
6461
editorFocusedRequestedLine,
6562
dragRowDivider,

src/actions/projects.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ export const unhideComponent = createAction(
3636
(_projectKey, _componentName, timestamp = Date.now()) => ({timestamp}),
3737
);
3838

39+
export const toggleComponent = createAction(
40+
'TOGGLE_COMPONENT',
41+
(projectKey, componentName) => ({projectKey, componentName}),
42+
(_projectKey, _componentName, timestamp = Date.now()) => ({timestamp}),
43+
);
44+
3945
export const gistImported = createAction(
4046
'GIST_IMPORTED',
4147
(projectKey, gistData) => ({projectKey, gistData}),

src/components/Dashboard.jsx

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/components/Instructions.jsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import remark from 'remark';
4+
import remarkReact from 'remark-react';
5+
import classnames from 'classnames';
6+
7+
export default function Instructions({instructions, isOpen}) {
8+
if (!instructions || !isOpen) {
9+
return null;
10+
}
11+
12+
return (
13+
<div
14+
className={classnames(
15+
'layout__instructions',
16+
'instructions',
17+
'u__flex-container',
18+
'u__flex-container_column',
19+
)}
20+
>
21+
{remark().use(remarkReact).processSync(instructions).contents}
22+
</div>
23+
);
24+
}
25+
26+
Instructions.propTypes = {
27+
instructions: PropTypes.string.isRequired,
28+
isOpen: PropTypes.bool.isRequired,
29+
};

src/components/Sidebar.jsx

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/components/Workspace.jsx

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import values from 'lodash/values';
66
import bindAll from 'lodash/bindAll';
77
import includes from 'lodash/includes';
88
import isNull from 'lodash/isNull';
9+
import get from 'lodash/get';
910
import partial from 'lodash/partial';
1011
import map from 'lodash/map';
1112
import {t} from 'i18next';
@@ -24,24 +25,23 @@ import {
2425
userLoggedOut,
2526
hideComponent,
2627
unhideComponent,
27-
toggleDashboard,
2828
focusLine,
2929
editorFocusedRequestedLine,
3030
dragRowDivider,
3131
dragColumnDivider,
3232
startDragColumnDivider,
3333
stopDragColumnDivider,
34+
toggleComponent,
3435
applicationLoaded,
3536

3637
} from '../actions';
3738

3839
import {isPristineProject} from '../util/projectUtils';
3940
import {getCurrentProject} from '../selectors';
4041

41-
import {TopBar, Dashboard, NotificationList} from '../containers';
42+
import {TopBar, Instructions, NotificationList} from '../containers';
4243
import EditorsColumn from './EditorsColumn';
4344
import Output from './Output';
44-
import Sidebar from './Sidebar';
4545
import PopThrobber from './PopThrobber';
4646

4747
function mapStateToProps(state) {
@@ -64,6 +64,7 @@ class Workspace extends React.Component {
6464
bindAll(
6565
this,
6666
'_handleUnload',
67+
'_handleClickInstructionsBar',
6768
'_handleComponentUnhide',
6869
'_handleComponentHide',
6970
'_handleDividerDrag',
@@ -72,7 +73,6 @@ class Workspace extends React.Component {
7273
'_handleEditorInput',
7374
'_handleEditorsDividerDrag',
7475
'_handleErrorClick',
75-
'_handleToggleDashboard',
7676
'_handleRequestedLineFocused',
7777
'_storeDividerRef',
7878
'_storeColumnRef',
@@ -185,10 +185,6 @@ class Workspace extends React.Component {
185185
);
186186
}
187187

188-
_handleToggleDashboard() {
189-
this.props.dispatch(toggleDashboard());
190-
}
191-
192188
_handleEditorsDividerDrag(data) {
193189
this.props.dispatch(dragRowDivider(data));
194190
}
@@ -204,14 +200,24 @@ class Workspace extends React.Component {
204200
this.props.dispatch(editorFocusedRequestedLine());
205201
}
206202

207-
_renderSidebar() {
203+
_handleClickInstructionsBar() {
204+
this.props.dispatch(toggleComponent(
205+
get(this.props, ['currentProject', 'projectKey']),
206+
'instructions',
207+
));
208+
}
209+
210+
_renderInstructionsBar() {
211+
if (!get(this.props, ['currentProject', 'instructions'])) {
212+
return null;
213+
}
214+
208215
return (
209-
<div className="layout__sidebar">
210-
<Sidebar
211-
dashboardIsOpen={this.props.ui.dashboard.isOpen}
212-
validationState={this._getOverallValidationState()}
213-
onToggleDashboard={this._handleToggleDashboard}
214-
/>
216+
<div
217+
className="layout__instructions-bar"
218+
onClick={this._handleClickInstructionsBar}
219+
>
220+
<span className="u__icon">&#xf05a;</span>
215221
</div>
216222
);
217223
}
@@ -290,8 +296,8 @@ class Workspace extends React.Component {
290296
<TopBar />
291297
<NotificationList />
292298
<div className="layout__columns">
293-
<Dashboard />
294-
{this._renderSidebar()}
299+
<Instructions />
300+
{this._renderInstructionsBar()}
295301
<div className="workspace layout__main">
296302
{this._renderEnvironment()}
297303
</div>

src/components/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import Dashboard from './Dashboard';
1+
import Instructions from './Instructions';
22
import ErrorReport from './ErrorReport';
33
import NotificationList from './NotificationList';
44
import Preview from './Preview';
55
import TopBar from './TopBar';
66
import ProjectPreview from './ProjectPreview';
77

88
export {
9-
Dashboard,
9+
Instructions,
1010
ErrorReport,
1111
NotificationList,
1212
Preview,
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import {connect} from 'react-redux';
2-
import {Dashboard} from '../components';
2+
import {Instructions} from '../components';
33
import {
44
getCurrentProjectInstructions,
5-
isDashboardOpen,
5+
getHiddenUIComponents,
66
} from '../selectors';
77

88
function mapStateToProps(state) {
99
return {
1010
instructions: getCurrentProjectInstructions(state),
11-
isOpen: isDashboardOpen(state),
11+
isOpen: !getHiddenUIComponents(state).includes('instructions'),
1212
};
1313
}
1414

1515
export default connect(
1616
mapStateToProps,
17-
)(Dashboard);
17+
)(Instructions);

src/containers/TopBar.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
getEnabledLibraries,
1111
getOpenTopBarMenu,
1212
getAllProjectKeys,
13-
isDashboardOpen,
1413
isExperimental,
1514
isGistExportInProgress,
1615
isSnapshotInProgress,
@@ -24,7 +23,6 @@ import {
2423
exportGist,
2524
exportRepo,
2625
notificationTriggered,
27-
toggleDashboard,
2826
toggleEditorTextSize,
2927
toggleLibrary,
3028
toggleTopBarMenu,
@@ -41,7 +39,6 @@ function mapStateToProps(state) {
4139
enabledLibraries: getEnabledLibraries(state),
4240
isExperimental: isExperimental(state),
4341
isGistExportInProgress: isGistExportInProgress(state),
44-
isHamburgerMenuActive: isDashboardOpen(state),
4542
isSnapshotInProgress: isSnapshotInProgress(state),
4643
isTextSizeLarge: isTextSizeLarge(state),
4744
isUserAuthenticated: isUserAuthenticated(state),
@@ -54,10 +51,6 @@ function mapStateToProps(state) {
5451

5552
function mapDispatchToProps(dispatch) {
5653
return {
57-
onClickHamburgerMenu() {
58-
dispatch(toggleDashboard());
59-
},
60-
6154
onClickMenu(menuKey) {
6255
dispatch(toggleTopBarMenu(menuKey));
6356
},

src/containers/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import Dashboard from './Dashboard';
21
import ErrorReport from './ErrorReport';
2+
import Instructions from './Instructions';
33
import NotificationList from './NotificationList';
44
import Preview from './Preview';
55
import ProjectPreview from './ProjectPreview';
66
import TopBar from './TopBar';
77

88
export {
9-
Dashboard,
109
ErrorReport,
10+
Instructions,
1111
NotificationList,
1212
Preview,
1313
ProjectPreview,

0 commit comments

Comments
 (0)