Skip to content
Merged
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 @@ -36,6 +36,7 @@ import useLocalize from '../../../../hooks/useLocalize';
import getModalState from '../../../../libs/getModalState';
import useWindowDimensions from '../../../../hooks/useWindowDimensions';
import * as EmojiPickerActions from '../../../../libs/actions/EmojiPickerAction';
import getDraftComment from '../../../../libs/ComposerUtils/getDraftComment';

const propTypes = {
/** A method to call when the form is submitted */
Expand Down Expand Up @@ -105,7 +106,6 @@ function ReportActionCompose({
reportID,
reportActions,
shouldShowComposeInput,
isCommentEmpty: isCommentEmptyProp,
}) {
const {translate} = useLocalize();
const {isMediumScreenWidth, isSmallScreenWidth} = useWindowDimensions();
Expand All @@ -125,7 +125,10 @@ function ReportActionCompose({
* Updates the should clear state of the composer
*/
const [textInputShouldClear, setTextInputShouldClear] = useState(false);
const [isCommentEmpty, setIsCommentEmpty] = useState(isCommentEmptyProp);
const [isCommentEmpty, setIsCommentEmpty] = useState(() => {
const draftComment = getDraftComment(reportID);
return !draftComment || !!draftComment.match(/^(\s)*$/);
});

/**
* Updates the visibility state of the menu
Expand Down Expand Up @@ -431,10 +434,6 @@ export default compose(
withNetwork(),
withCurrentUserPersonalDetails,
withOnyx({
isCommentEmpty: {
key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`,
selector: (comment) => _.isEmpty(comment),
},

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I modified the solution a little bit because I found an issue with the onyx selector.

When the draft comment onyx is updated, the selector is triggered twice with different values.
First, the value will be boolean (wrong) and the second one will be the comment itself (correct).

The boolean value is based on what we return on the selector. For example, if the comment is empty, the selector will be triggered with true and the comment value.

As the above isCommentEmpty prop is only used to initialize the isCommentEmpty state, I use a lazy init for the state which takes the draft comment with getDraftComment. We did the same pattern here too:

const [value, setValue] = useState(() => getDraftComment(reportID) || '');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks good to me 👍🏼

blockedFromConcierge: {
key: ONYXKEYS.NVP_BLOCKED_FROM_CONCIERGE,
},
Expand Down