2017-07-31 20:04:01 -07:00
|
|
|
import { ofType } from 'redux-epic';
|
|
|
|
import {
|
|
|
|
types,
|
|
|
|
closeBugModal,
|
|
|
|
|
|
|
|
filesSelector
|
|
|
|
} from '../redux';
|
|
|
|
|
|
|
|
import { currentChallengeSelector } from '../../../redux';
|
2016-07-11 21:54:55 -07:00
|
|
|
|
|
|
|
function filesToMarkdown(files = {}) {
|
|
|
|
const moreThenOneFile = Object.keys(files).length > 1;
|
|
|
|
return Object.keys(files).reduce((fileString, key) => {
|
|
|
|
const file = files[key];
|
|
|
|
if (!file) {
|
|
|
|
return fileString;
|
|
|
|
}
|
|
|
|
const fileName = moreThenOneFile ? `\\ file: ${file.contents}` : '';
|
|
|
|
const fileType = file.ext;
|
2017-01-25 21:33:05 +01:00
|
|
|
return fileString +
|
|
|
|
'\`\`\`' +
|
|
|
|
fileType +
|
|
|
|
'\n' +
|
|
|
|
fileName +
|
|
|
|
'\n' +
|
|
|
|
file.contents +
|
|
|
|
'\n' +
|
|
|
|
'\`\`\`\n\n';
|
2016-07-11 21:54:55 -07:00
|
|
|
}, '\n');
|
|
|
|
}
|
|
|
|
|
2017-07-31 20:04:01 -07:00
|
|
|
export default function bugEpic(actions, { getState }, { window }) {
|
|
|
|
return actions::ofType(types.openIssueSearch, types.createIssue)
|
2016-07-11 21:54:55 -07:00
|
|
|
.map(({ type }) => {
|
2017-07-31 20:04:01 -07:00
|
|
|
const state = getState();
|
|
|
|
const files = filesSelector(state);
|
|
|
|
const challengeName = currentChallengeSelector(state);
|
2016-07-11 21:54:55 -07:00
|
|
|
const {
|
|
|
|
navigator: { userAgent },
|
|
|
|
location: { href }
|
|
|
|
} = window;
|
2017-05-21 15:00:35 -04:00
|
|
|
let titleText = challengeName;
|
2016-07-11 21:54:55 -07:00
|
|
|
if (type === types.openIssueSearch) {
|
|
|
|
window.open(
|
2017-08-26 00:07:44 +02:00
|
|
|
'https://forum.freecodecamp.org/search?q=' +
|
2017-05-21 15:00:35 -04:00
|
|
|
window.encodeURIComponent(titleText)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
titleText = 'Need assistance in ' + challengeName;
|
|
|
|
let textMessage = [
|
|
|
|
'#### Challenge Name\n',
|
|
|
|
'[',
|
|
|
|
challengeName,
|
|
|
|
'](',
|
|
|
|
href,
|
|
|
|
') has an issue.\n',
|
|
|
|
'#### Issue Description\n',
|
|
|
|
'<!-- Describe below when the issue happens and how to ',
|
|
|
|
'reproduce it -->\n\n\n',
|
|
|
|
'#### Browser Information\n',
|
|
|
|
'<!-- Describe your workspace in which you are having issues-->\n',
|
|
|
|
'User Agent is: <code>',
|
|
|
|
userAgent,
|
|
|
|
'</code>.\n\n',
|
|
|
|
'#### Screenshot\n',
|
|
|
|
'<!-- Add a screenshot of your issue -->\n\n\n',
|
|
|
|
'#### Your Code'
|
|
|
|
].join('');
|
|
|
|
const body = filesToMarkdown(files);
|
|
|
|
if (body.length > 10) {
|
|
|
|
textMessage = textMessage + body;
|
|
|
|
}
|
|
|
|
window.open(
|
2017-08-26 00:07:44 +02:00
|
|
|
'https://forum.freecodecamp.org/new-topic?category=General&title=' +
|
2017-05-21 15:00:35 -04:00
|
|
|
window.encodeURIComponent(titleText) + '&body=' +
|
|
|
|
window.encodeURIComponent(textMessage),
|
|
|
|
'_blank'
|
2016-07-11 21:54:55 -07:00
|
|
|
);
|
|
|
|
}
|
2017-05-21 15:00:35 -04:00
|
|
|
|
2016-07-11 21:54:55 -07:00
|
|
|
return closeBugModal();
|
|
|
|
});
|
|
|
|
}
|