2019-08-28 21:55:56 +05:30
|
|
|
import dedent from 'dedent';
|
2018-05-08 00:29:45 +01:00
|
|
|
import { ofType } from 'redux-observable';
|
|
|
|
import {
|
|
|
|
types,
|
|
|
|
closeModal,
|
|
|
|
challengeFilesSelector,
|
2021-02-09 05:53:10 +00:00
|
|
|
challengeMetaSelector,
|
|
|
|
projectFormValuesSelector
|
2018-05-08 00:29:45 +01:00
|
|
|
} from '../redux';
|
2018-09-30 11:37:19 +01:00
|
|
|
import { tap, mapTo } from 'rxjs/operators';
|
2021-03-26 00:43:43 +05:30
|
|
|
import envData from '../../../../../config/env.json';
|
|
|
|
|
|
|
|
const { forumLocation } = envData;
|
2018-05-08 00:29:45 +01: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;
|
2019-08-28 21:55:56 +05:30
|
|
|
return `${fileString}\`\`\`${fileType}\n${fileName}\n${file.contents}\n\`\`\`\n\n`;
|
2018-05-08 00:29:45 +01:00
|
|
|
}, '\n');
|
|
|
|
}
|
|
|
|
|
2018-09-30 11:37:19 +01:00
|
|
|
function createQuestionEpic(action$, state$, { window }) {
|
2018-05-08 00:29:45 +01:00
|
|
|
return action$.pipe(
|
|
|
|
ofType(types.createQuestion),
|
|
|
|
tap(() => {
|
2018-09-30 11:37:19 +01:00
|
|
|
const state = state$.value;
|
2018-05-08 00:29:45 +01:00
|
|
|
const files = challengeFilesSelector(state);
|
2020-10-30 20:10:34 +01:00
|
|
|
const { title: challengeTitle, helpCategory } = challengeMetaSelector(
|
|
|
|
state
|
|
|
|
);
|
2018-07-24 18:00:36 +05:30
|
|
|
const {
|
2018-09-30 11:37:19 +01:00
|
|
|
navigator: { userAgent },
|
|
|
|
location: { href }
|
|
|
|
} = window;
|
2021-02-09 05:53:10 +00:00
|
|
|
const projectFormValues = Object.entries(
|
|
|
|
projectFormValuesSelector(state)
|
|
|
|
);
|
2019-08-28 21:55:56 +05:30
|
|
|
const endingText = dedent(
|
|
|
|
`**Your browser information:**
|
|
|
|
|
|
|
|
User Agent is: <code>${userAgent}</code>.
|
|
|
|
|
|
|
|
**Challenge:** ${challengeTitle}
|
|
|
|
|
|
|
|
**Link to the challenge:**
|
|
|
|
${href}`
|
|
|
|
);
|
|
|
|
|
|
|
|
let textMessage = dedent(
|
2021-02-09 05:53:10 +00:00
|
|
|
`**Tell us what's happening:**
|
2021-04-18 17:40:26 +01:00
|
|
|
Describe your issue in detail here.
|
2021-02-11 06:42:51 +00:00
|
|
|
|
2021-02-09 05:53:10 +00:00
|
|
|
${
|
|
|
|
projectFormValues.length
|
|
|
|
? `**Your project link(s)**\n`
|
|
|
|
: `**Your code so far**`
|
|
|
|
}
|
2021-03-11 00:31:46 +05:30
|
|
|
${
|
|
|
|
projectFormValues
|
|
|
|
?.map(([key, val]) => `${key}: ${val}\n`)
|
|
|
|
?.join('') || filesToMarkdown(files)
|
|
|
|
}
|
2021-02-11 06:42:51 +00:00
|
|
|
|
2021-02-09 05:53:10 +00:00
|
|
|
${endingText}`
|
2018-05-08 00:29:45 +01:00
|
|
|
);
|
2019-08-28 21:55:56 +05:30
|
|
|
|
|
|
|
const altTextMessage = dedent(
|
|
|
|
`**Tell us what's happening:**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
**Your code so far**
|
|
|
|
|
|
|
|
WARNING
|
|
|
|
|
|
|
|
The challenge seed code and/or your solution exceeded the maximum length we can port over from the challenge.
|
|
|
|
|
|
|
|
You will need to take an additional step here so the code you wrote presents in an easy to read format.
|
|
|
|
|
|
|
|
Please copy/paste all the editor code showing in the challenge from where you just linked.
|
|
|
|
|
|
|
|
\`\`\`
|
|
|
|
|
|
|
|
Replace these two sentences with your copied code.
|
2020-10-30 20:10:34 +01:00
|
|
|
Please leave the \`\`\` line above and the \`\`\` line below,
|
2019-08-28 21:55:56 +05:30
|
|
|
because they allow your code to properly format in the post.
|
|
|
|
|
|
|
|
\`\`\`\n${endingText}`
|
|
|
|
);
|
|
|
|
|
2020-10-30 20:10:34 +01:00
|
|
|
const category = window.encodeURIComponent(helpCategory || 'Help');
|
2019-08-28 21:55:56 +05:30
|
|
|
|
|
|
|
const studentCode = window.encodeURIComponent(textMessage);
|
|
|
|
const altStudentCode = window.encodeURIComponent(altTextMessage);
|
|
|
|
|
|
|
|
const baseURI = `${forumLocation}/new-topic?category=${category}&title=&body=`;
|
|
|
|
const defaultURI = `${baseURI}${studentCode}`;
|
|
|
|
const altURI = `${baseURI}${altStudentCode}`;
|
|
|
|
|
|
|
|
window.open(defaultURI.length < 8000 ? defaultURI : altURI, '_blank');
|
2018-05-08 00:29:45 +01:00
|
|
|
}),
|
|
|
|
mapTo(closeModal('help'))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default createQuestionEpic;
|