From 61d8a29b208d3067edce41b812d7481f54e31126 Mon Sep 17 00:00:00 2001 From: Ritvik Nag Date: Sun, 11 Feb 2024 13:37:33 -0500 Subject: [PATCH] fix: don't copy to clipboard if textbox is empty --- src/components/medium/medium.js | 40 +++++++++++++-------------- src/components/textfield/textfield.js | 6 ++-- src/state.js | 2 +- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/components/medium/medium.js b/src/components/medium/medium.js index ef59087..0b25a87 100644 --- a/src/components/medium/medium.js +++ b/src/components/medium/medium.js @@ -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 = ( -
- {(copySuccess && ( -

- Copied to Clipboard! + const copyStatusMessage = ( +
+ {(copySuccess && ( +

+ Copied to Clipboard! +

+ )) || + (copySuccess === undefined && ( +

+ Waiting to copy rich text...

)) ||

Error!

} -
- ); - } else { - text = ( -
-

- Waiting to copy rich text... -

-
- ); - } +

+ ); - return
; + return ( +
+ ); }; export default connect(state => ({ diff --git a/src/components/textfield/textfield.js b/src/components/textfield/textfield.js index 699f864..6c2e0d5 100644 --- a/src/components/textfield/textfield.js +++ b/src/components/textfield/textfield.js @@ -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; diff --git a/src/state.js b/src/state.js index ac0c5d3..2635e8f 100644 --- a/src/state.js +++ b/src/state.js @@ -9,7 +9,7 @@ export function setContent(content, copySuccess) { export function reducer( state = { content: '', - copySuccess: false, + copySuccess: undefined, }, action ) {