fix(client): forum help and hints (#36625)
* fix(client): add warning on exceeding forum post length limit Co-authored-by: Mrugesh Mohapatra <1884376+raisedadead@users.noreply.github.com> * fix: corrected guide url for backend challenges and projects * fix: moved getGuideUrl to utils * fix: added forumTopicId to ChallengeNode PropTypes * fix: conolidated helpers and add base url to env.json * fix: made use template literals * tests: created unit tests for getGuideUrl * fix: add characters which will be encoded Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: use encoded version of title Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com> * fix: encode title Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import dedent from 'dedent';
|
||||
import { ofType } from 'redux-observable';
|
||||
import {
|
||||
types,
|
||||
@@ -7,6 +8,7 @@ import {
|
||||
} from '../redux';
|
||||
import { tap, mapTo } from 'rxjs/operators';
|
||||
import { helpCategory } from '../../../../utils/challengeTypes';
|
||||
import { forumLocation } from '../../../../../config/env.json';
|
||||
|
||||
function filesToMarkdown(files = {}) {
|
||||
const moreThenOneFile = Object.keys(files).length > 1;
|
||||
@@ -17,17 +19,7 @@ function filesToMarkdown(files = {}) {
|
||||
}
|
||||
const fileName = moreThenOneFile ? `\\ file: ${file.contents}` : '';
|
||||
const fileType = file.ext;
|
||||
return (
|
||||
fileString +
|
||||
'```' +
|
||||
fileType +
|
||||
'\n' +
|
||||
fileName +
|
||||
'\n' +
|
||||
file.contents +
|
||||
'\n' +
|
||||
'```\n\n'
|
||||
);
|
||||
return `${fileString}\`\`\`${fileType}\n${fileName}\n${file.contents}\n\`\`\`\n\n`;
|
||||
}, '\n');
|
||||
}
|
||||
|
||||
@@ -44,28 +36,59 @@ function createQuestionEpic(action$, state$, { window }) {
|
||||
navigator: { userAgent },
|
||||
location: { href }
|
||||
} = window;
|
||||
const textMessage = [
|
||||
"**Tell us what's happening:**\n\n\n\n",
|
||||
'**Your code so far**\n',
|
||||
filesToMarkdown(files),
|
||||
'**Your browser information:**\n\n',
|
||||
'User Agent is: `',
|
||||
userAgent,
|
||||
'`.\n\n',
|
||||
'**Challenge:**\n',
|
||||
challengeTitle,
|
||||
'\n**Link to the challenge:**\n',
|
||||
href
|
||||
].join('');
|
||||
window.open(
|
||||
'https://forum.freecodecamp.org/new-topic' +
|
||||
'?category=' +
|
||||
window.encodeURIComponent(helpCategory[challengeType] || 'Help') +
|
||||
'&title=' +
|
||||
'&body=' +
|
||||
window.encodeURIComponent(textMessage),
|
||||
'_blank'
|
||||
|
||||
const endingText = dedent(
|
||||
`**Your browser information:**
|
||||
|
||||
User Agent is: <code>${userAgent}</code>.
|
||||
|
||||
**Challenge:** ${challengeTitle}
|
||||
|
||||
**Link to the challenge:**
|
||||
${href}`
|
||||
);
|
||||
|
||||
let textMessage = dedent(
|
||||
`**Tell us what's happening:**\n\n\n\n**Your code so far**
|
||||
${filesToMarkdown(files)}\n${endingText}`
|
||||
);
|
||||
|
||||
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.
|
||||
Please leave the \`\`\` line above and the \`\`\` line below,
|
||||
because they allow your code to properly format in the post.
|
||||
|
||||
\`\`\`\n${endingText}`
|
||||
);
|
||||
|
||||
const category = window.encodeURIComponent(
|
||||
helpCategory[challengeType] || 'Help'
|
||||
);
|
||||
|
||||
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');
|
||||
}),
|
||||
mapTo(closeModal('help'))
|
||||
);
|
||||
|
Reference in New Issue
Block a user