Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import PropTypes from 'prop-types';

import { annotationShape, fileShape } from '../../propTypes';
import translations from '../../translations';
import CopyCodeButton from '../answers/Programming/CopyCodeButton';
import ProgrammingFileDownloadChip from '../answers/Programming/ProgrammingFileDownloadChip';

import NarrowEditor from './NarrowEditor';
Expand Down Expand Up @@ -212,7 +213,10 @@ class ReadOnlyEditor extends Component {
return (
<>
<div className="flex items-center justify-between mt-2">
<ProgrammingFileDownloadChip file={file} />
<div className="flex items-center gap-2">
<ProgrammingFileDownloadChip file={file} />
<CopyCodeButton file={file} />
</div>
<div>
{this.renderShowCommentsPanel()}
{this.renderExpandAllToggle()}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { FC } from 'react';
import { ContentCopy } from '@mui/icons-material';
import { Chip } from '@mui/material';
import { ProgrammingContent } from 'types/course/assessment/submission/answer/programming';

import toast from 'lib/hooks/toast';

interface Props {
file: ProgrammingContent;
}

const CopyCodeButton: FC<Props> = (props) => {
const { file } = props;

const handleCopy = (): void => {
navigator.clipboard.writeText(file.content).then(() => {
toast.success('Copied to clipboard');
});
};

return (
<Chip
className="copy-code-button"
icon={<ContentCopy />}
label="Copy"
onClick={handleCopy}
size="small"
variant="outlined"
/>
);
};

export default CopyCodeButton;