Skip to content

Commit 886aec3

Browse files
committed
Created a button to copy text, does not copy the correct text but plan to fix it soon
1 parent f512cae commit 886aec3

File tree

1 file changed

+46
-34
lines changed

1 file changed

+46
-34
lines changed

frontend/src/App.js

Lines changed: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -390,40 +390,52 @@ const CourseText = (
390390
page,
391391
pages,
392392
assistant,
393-
}) =>
394-
<>
395-
<h1 dangerouslySetInnerHTML={{__html: page.title}}/>
396-
{page.steps.map((part, index) =>
397-
<div
398-
key={index}
399-
id={`step-text-${index}`}
400-
className={index > 0 ? 'pt-3' : ''}
401-
style={index > step.index ? {display: 'none'} : {}}
402-
>
403-
<Markdown html={part.text} copyFunc={text => bookSetState("editorContent", text)}/>
404-
<hr style={{ margin: '0' }}/>
405-
</div>
406-
)}
407-
<Assistant {...assistant} step={step}/>
408-
{/* pt-3 is Bootstrap's helper class. Shorthand for padding-top: 1rem. Available classes are pt-{1-5} */}
409-
<div className='pt-3'>
410-
{page.index > 0 &&
411-
<button className="btn btn-primary previous-button"
412-
onClick={() => movePage(-1)}>
413-
{terms.previous}
414-
</button>}
415-
{" "}
416-
{page.index < Object.keys(pages).length - 1 && step.index === page.steps.length - 1 &&
417-
<button className="btn btn-success next-button"
418-
onClick={() => movePage(+1)}>
419-
{terms.next}
420-
</button>}
421-
</div>
422-
<br/>
423-
{
424-
user.developerMode && <StepButtons/>
425-
}
426-
</>
393+
}) => {
394+
const copyTextToClipboard = () => {
395+
const stepText = page.steps[step.index].text;
396+
navigator.clipboard.writeText(stepText);
397+
};
398+
399+
return (
400+
<>
401+
<h1 dangerouslySetInnerHTML={{__html: page.title}}/>
402+
{page.steps.map((part, index) =>
403+
<div
404+
key={index}
405+
id={`step-text-${index}`}
406+
className={index > 0 ? 'pt-3' : ''}
407+
style={index > step.index ? {display: 'none'} : {}}
408+
>
409+
<Markdown html={part.text} copyFunc={text => bookSetState("editorContent", text)}/>
410+
<hr style={{ margin: '0' }}/>
411+
</div>
412+
)}
413+
<Assistant {...assistant} step={step}/>
414+
<div className='pt-3'>
415+
{page.index > 0 &&
416+
<button className="btn btn-primary previous-button"
417+
onClick={() => movePage(-1)}>
418+
{terms.previous}
419+
</button>}
420+
{" "}
421+
{page.index < Object.keys(pages).length - 1 && step.index === page.steps.length - 1 &&
422+
<button className="btn btn-success next-button"
423+
onClick={() => movePage(+1)}>
424+
{terms.next}
425+
</button>}
426+
{" "}
427+
{step.index === page.steps.length - 1 &&
428+
<button className="btn btn-secondary copy-button"
429+
onClick={copyTextToClipboard}>
430+
{terms.copy}
431+
</button>}
432+
</div>
433+
<br/>
434+
{user.developerMode && <StepButtons/>}
435+
</>
436+
);
437+
};
438+
427439

428440
class AppComponent extends React.Component {
429441
render() {

0 commit comments

Comments
 (0)