Skip to content
Merged
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
30 changes: 28 additions & 2 deletions src/components/LHNOptionsList/OptionRowLHN.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import _ from 'underscore';
import React from 'react';
import React, {useEffect} from 'react';
import PropTypes from 'prop-types';
import {View, StyleSheet} from 'react-native';
import lodashGet from 'lodash/get';
import * as optionRowStyles from '../../styles/optionRowStyles';
import styles from '../../styles/styles';
import * as StyleUtils from '../../styles/StyleUtils';
Expand All @@ -12,6 +13,7 @@ import Hoverable from '../Hoverable';
import DisplayNames from '../DisplayNames';
import colors from '../../styles/colors';
import withLocalize, {withLocalizePropTypes} from '../withLocalize';
import {withReportCommentDrafts} from '../OnyxProvider';
import Text from '../Text';
import SubscriptAvatar from '../SubscriptAvatar';
import CONST from '../../CONST';
Expand All @@ -23,12 +25,18 @@ import PressableWithSecondaryInteraction from '../PressableWithSecondaryInteract
import * as ReportActionContextMenu from '../../pages/home/report/ContextMenu/ReportActionContextMenu';
import * as ContextMenuActions from '../../pages/home/report/ContextMenu/ContextMenuActions';
import * as OptionsListUtils from '../../libs/OptionsListUtils';
import compose from '../../libs/compose';
import ONYXKEYS from '../../ONYXKEYS';
import * as Report from '../../libs/actions/Report';

const propTypes = {
/** Style for hovered state */
// eslint-disable-next-line react/forbid-prop-types
hoverStyle: PropTypes.object,

/** The comment left by the user */
comment: PropTypes.string,

/** The ID of the report that the option is for */
reportID: PropTypes.string.isRequired,

Expand All @@ -52,11 +60,20 @@ const defaultProps = {
onSelectRow: () => {},
isFocused: false,
style: null,
comment: '',
};

function OptionRowLHN(props) {
const optionItem = SidebarUtils.getOptionData(props.reportID);

useEffect(() => {
if (!optionItem || optionItem.hasDraftComment || !props.comment || props.comment.length <= 0 || props.isFocused) {
return;
}
Comment thread
procrastagonist marked this conversation as resolved.
Comment thread
procrastagonist marked this conversation as resolved.
Report.setReportWithDraft(props.reportID, true);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

if (!optionItem) {
return null;
}
Expand Down Expand Up @@ -255,4 +272,13 @@ OptionRowLHN.propTypes = propTypes;
OptionRowLHN.defaultProps = defaultProps;
OptionRowLHN.displayName = 'OptionRowLHN';

export default withLocalize(OptionRowLHN);
export default compose(
withLocalize,
withReportCommentDrafts({
propName: 'comment',
transformValue: (drafts, props) => {
const draftKey = `${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${props.reportID}`;
return lodashGet(drafts, draftKey, '');
},
}),
Comment thread
procrastagonist marked this conversation as resolved.
)(OptionRowLHN);
15 changes: 13 additions & 2 deletions src/components/OnyxProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const [withCurrentDate, CurrentDateProvider] = createOnyxContext(ONYXKEYS.CURREN
const [withReportActionsDrafts, ReportActionsDraftsProvider] = createOnyxContext(ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS);
const [withBlockedFromConcierge, BlockedFromConciergeProvider] = createOnyxContext(ONYXKEYS.NVP_BLOCKED_FROM_CONCIERGE);
const [withBetas, BetasProvider] = createOnyxContext(ONYXKEYS.BETAS);
const [withReportCommentDrafts, ReportCommentDraftsProvider] = createOnyxContext(ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT);
Comment thread
procrastagonist marked this conversation as resolved.

const propTypes = {
/** Rendered child component */
Expand All @@ -20,7 +21,17 @@ const propTypes = {

function OnyxProvider(props) {
return (
<ComposeProviders components={[NetworkProvider, PersonalDetailsProvider, ReportActionsDraftsProvider, CurrentDateProvider, BlockedFromConciergeProvider, BetasProvider]}>
<ComposeProviders
components={[
NetworkProvider,
PersonalDetailsProvider,
ReportActionsDraftsProvider,
CurrentDateProvider,
BlockedFromConciergeProvider,
BetasProvider,
ReportCommentDraftsProvider,
]}
>
{props.children}
</ComposeProviders>
);
Expand All @@ -31,4 +42,4 @@ OnyxProvider.propTypes = propTypes;

export default OnyxProvider;

export {withNetwork, withPersonalDetails, withReportActionsDrafts, withCurrentDate, withBlockedFromConcierge, withBetas, NetworkContext};
export {withNetwork, withPersonalDetails, withReportActionsDrafts, withCurrentDate, withBlockedFromConcierge, withBetas, NetworkContext, withReportCommentDrafts};
4 changes: 4 additions & 0 deletions src/pages/home/report/ReportActionCompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ class ReportActionCompose extends React.Component {
showPopoverMenu: this.showPopoverMenu,
});
}

if (this.props.comment.length !== 0) {
Report.setReportWithDraft(this.props.reportID, true);
}
}

componentDidUpdate(prevProps) {
Expand Down