Skip to content

Commit 65db795

Browse files
authored
Merge pull request #988 from inlinestyle/by-readme
Project README
2 parents 8aa8a97 + 049b91c commit 65db795

12 files changed

Lines changed: 504 additions & 27 deletions

File tree

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@
141141
"redux-logger": "^3.0.6",
142142
"redux-saga": "^0.15.3",
143143
"redux-saga-debounce-effect": "https://github.com/madewithlove/redux-saga-debounce-effect.git#v0.2.2",
144+
"remark": "^8.0.0",
145+
"remark-react": "^4.0.0",
144146
"reselect": "^3.0.1",
145147
"rxjs": "^5.0.2",
146148
"slowparse": "^1.1.4",

src/clients/github.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ function buildGistFromProject(project) {
108108
language: 'JavaScript',
109109
};
110110
}
111+
if (trim(project.instructions)) {
112+
files['README.md'] = {
113+
content: project.instructions,
114+
language: 'Markdown',
115+
};
116+
}
111117
if (project.enabledLibraries.length || project.hiddenUIComponents.length) {
112118
files['popcode.json'] = {
113119
content: createPopcodeJson(project),

src/components/Dashboard.jsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3+
import remark from 'remark';
4+
import remarkReact from 'remark-react';
35
import {t} from 'i18next';
46
import classnames from 'classnames';
57
import config from '../config';
@@ -75,7 +77,8 @@ class Dashboard extends React.Component {
7577
}
7678

7779
render() {
78-
if (!this.props.isOpen) {
80+
const {instructions, isOpen} = this.props;
81+
if (!isOpen) {
7982
return null;
8083
}
8184

@@ -89,6 +92,9 @@ class Dashboard extends React.Component {
8992
return (
9093
<div className={sidebarClassnames}>
9194
{this._renderMenu()}
95+
<div className="dashboard__instructions">
96+
{remark().use(remarkReact).processSync(instructions).contents}
97+
</div>
9298
<div className="dashboard__spacer" />
9399
{this._renderLinks()}
94100
</div>
@@ -99,6 +105,7 @@ class Dashboard extends React.Component {
99105
Dashboard.propTypes = {
100106
currentUser: PropTypes.object.isRequired,
101107
gistExportInProgress: PropTypes.bool.isRequired,
108+
instructions: PropTypes.string.isRequired,
102109
isExperimental: PropTypes.bool.isRequired,
103110
isOpen: PropTypes.bool.isRequired,
104111
onExportGist: PropTypes.func.isRequired,

src/containers/Dashboard.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
exportRepo,
66
} from '../actions';
77
import {
8-
getCurrentProject,
8+
getCurrentProjectInstructions,
99
getCurrentUser,
1010
isDashboardOpen,
1111
isExperimental,
@@ -14,9 +14,9 @@ import {
1414

1515
function mapStateToProps(state) {
1616
return {
17-
currentProject: getCurrentProject(state),
1817
currentUser: getCurrentUser(state),
1918
gistExportInProgress: isGistExportInProgress(state),
19+
instructions: getCurrentProjectInstructions(state),
2020
isExperimental: isExperimental(state),
2121
isOpen: isDashboardOpen(state),
2222
};

src/css/application.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,10 @@ body {
370370
font-weight: bold;
371371
}
372372

373+
.dashboard__instructions {
374+
overflow: scroll;
375+
}
376+
373377
.dashboard__spacer {
374378
flex: 1 0 auto;
375379
}

src/records/Project.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,23 @@ export default class Project extends Record({
1414
enabledLibraries: new Set(),
1515
hiddenUIComponents: new Set(),
1616
updatedAt: null,
17+
instructions: '',
1718
}) {
1819
static fromJS({
1920
projectKey = null,
2021
sources = {},
2122
enabledLibraries = [],
2223
hiddenUIComponents = [],
2324
updatedAt = null,
25+
instructions = '',
2426
}) {
2527
return new Project({
2628
projectKey,
2729
sources: new Sources(sources),
2830
enabledLibraries: new Set(enabledLibraries),
2931
hiddenUIComponents: new Set(hiddenUIComponents),
3032
updatedAt,
33+
instructions,
3134
});
3235
}
3336
}

src/reducers/projects.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import filter from 'lodash/filter';
44
import find from 'lodash/find';
55
import get from 'lodash/get';
66
import map from 'lodash/map';
7+
import sortBy from 'lodash/sortBy';
78
import values from 'lodash/values';
89

910
import {Project} from '../records';
@@ -28,6 +29,14 @@ function unhideComponent(state, projectKey, component, timestamp) {
2829
).setIn([projectKey, 'updatedAt'], timestamp);
2930
}
3031

32+
function contentForLanguage(files, language) {
33+
const filesForLanguage = sortBy(
34+
filter(files, {language}),
35+
file => file.filename,
36+
);
37+
return map(filesForLanguage, 'content').join('\n\n');
38+
}
39+
3140
function importGist(state, projectKey, gistData) {
3241
const files = values(gistData.files);
3342
const popcodeJsonFile = find(files, {filename: 'popcode.json'});
@@ -39,12 +48,12 @@ function importGist(state, projectKey, gistData) {
3948
projectKey,
4049
sources: {
4150
html: get(find(files, {language: 'HTML'}), 'content', ''),
42-
css: map(filter(files, {language: 'CSS'}), 'content').join('\n\n'),
43-
javascript: map(filter(files, {language: 'JavaScript'}), 'content').
44-
join('\n\n'),
51+
css: contentForLanguage(files, 'CSS'),
52+
javascript: contentForLanguage(files, 'JavaScript'),
4553
},
4654
enabledLibraries: popcodeJson.enabledLibraries || [],
4755
hiddenUIComponents: popcodeJson.hiddenUIComponents || [],
56+
instructions: contentForLanguage(files, 'Markdown'),
4857
},
4958
);
5059
}

src/selectors/getCurrentProject.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import {createSelector} from 'reselect';
22
import getCurrentProjectKey from './getCurrentProjectKey';
3-
4-
function getProjects(state) {
5-
return state.get('projects');
6-
}
3+
import getProjects from './getProjects';
74

85
export default createSelector(
96
[getCurrentProjectKey, getProjects],
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {createSelector} from 'reselect';
2+
import getCurrentProjectKey from './getCurrentProjectKey';
3+
import getProjects from './getProjects';
4+
5+
export default createSelector(
6+
[getCurrentProjectKey, getProjects],
7+
(projectKey, projects) =>
8+
projectKey ? projects.getIn([projectKey, 'instructions']) : '',
9+
);

src/selectors/getProjects.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function getProjects(state) {
2+
return state.get('projects');
3+
}

0 commit comments

Comments
 (0)