Skip to content

Commit

Permalink
fix: don't copy to clipboard if textbox is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
rnag committed Feb 11, 2024
1 parent 1d728ee commit 61d8a29
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
40 changes: 19 additions & 21 deletions src/components/medium/medium.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,29 @@ import './medium.css';
import { connect } from 'react-redux';

const Medium = props => {
const { content, copySuccess } = props;
const { content: _, copySuccess } = props;

let text;

if (content) {
text = (
<div>
{(copySuccess && (
<h3 style={{ color: 'green' }}>
Copied to Clipboard!
const copyStatusMessage = (
<div>
{(copySuccess && (
<h3 style={{ color: 'green' }}>
Copied to Clipboard!
</h3>
)) ||
(copySuccess === undefined && (
<h3 style={{ color: 'gray' }}>
Waiting to copy rich text...
</h3>
)) || <h3 style={{ color: 'red' }}>Error!</h3>}
</div>
);
} else {
text = (
<div>
<h3 style={{ color: 'gray' }}>
Waiting to copy rich text...
</h3>
</div>
);
}
</div>
);

return <div id="medium" className="medium" children={text}></div>;
return (
<div
id="medium"
className="medium"
children={copyStatusMessage}></div>
);
};

export default connect(state => ({
Expand Down
6 changes: 4 additions & 2 deletions src/components/textfield/textfield.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ const TextField = props => {
let copySuccess;

try {
await copyRichToClip(converter(contentVal));
copySuccess = true;
if (contentVal) {
await copyRichToClip(converter(contentVal));
copySuccess = true;
} else copySuccess = undefined;
} catch (e) {
console.log('Fail', e);
copySuccess = false;
Expand Down
2 changes: 1 addition & 1 deletion src/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function setContent(content, copySuccess) {
export function reducer(
state = {
content: '',
copySuccess: false,
copySuccess: undefined,
},
action
) {
Expand Down

0 comments on commit 61d8a29

Please sign in to comment.