From fd2f8246adfa84dd24bdce30728c5e6d04d7f1ee Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Wed, 11 Aug 2021 10:02:13 -1000 Subject: [PATCH 1/2] consolidate Onyx.connect call Fix the context methods more report screen organizing create more context helpers remove bad merged code remove unusued imports and fix style undo context changes remove unused line add missing session --- src/components/createOnyxContext.js | 2 +- src/pages/home/ReportScreen.js | 9 ++++++++- src/pages/home/report/ReportActionCompose.js | 16 +++------------- src/pages/home/report/ReportActionsView.js | 14 -------------- 4 files changed, 12 insertions(+), 29 deletions(-) diff --git a/src/components/createOnyxContext.js b/src/components/createOnyxContext.js index 9304efd4a43..7b8d8b68983 100644 --- a/src/components/createOnyxContext.js +++ b/src/components/createOnyxContext.js @@ -26,7 +26,7 @@ export default (onyxKeyName) => { }, })(Provider); - const withOnyxKey = ({propName = onyxKeyName, transformValue = () => {}} = {}) => (WrappedComponent) => { + const withOnyxKey = ({propName = onyxKeyName, transformValue} = {}) => (WrappedComponent) => { const Consumer = forwardRef((props, ref) => ( {(value) => { diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index c782cb47bf7..d411fb5d1cd 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -134,7 +134,14 @@ class ReportScreen extends React.Component { - {!this.shouldShowLoader() && } + {!this.shouldShowLoader() && ( + + )} {this.props.session.shouldShowComposeInput && ( Keyboard.dismiss()}> `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, - canEvict: false, - }, - report: { - key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, - }, blockedFromConcierge: { key: ONYXKEYS.NVP_BLOCKED_FROM_CONCIERGE, }, diff --git a/src/pages/home/report/ReportActionsView.js b/src/pages/home/report/ReportActionsView.js index 29a39f9881c..c07c6b5f655 100755 --- a/src/pages/home/report/ReportActionsView.js +++ b/src/pages/home/report/ReportActionsView.js @@ -8,7 +8,6 @@ import { import PropTypes from 'prop-types'; import _ from 'underscore'; import lodashGet from 'lodash/get'; -import {withOnyx} from 'react-native-onyx'; import Text from '../../../components/Text'; import { fetchActions, @@ -18,7 +17,6 @@ import { subscribeToReportTypingEvents, unsubscribeFromReportChannel, } from '../../../libs/actions/Report'; -import ONYXKEYS from '../../../ONYXKEYS'; import ReportActionItem from './ReportActionItem'; import styles from '../../../styles/styles'; import ReportActionPropTypes from './ReportActionPropTypes'; @@ -457,16 +455,4 @@ export default compose( withWindowDimensions, withDrawerState, withLocalize, - withOnyx({ - report: { - key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, - }, - reportActions: { - key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, - canEvict: false, - }, - session: { - key: ONYXKEYS.SESSION, - }, - }), )(ReportActionsView); From 5ec26872dc8b16f360d4cde9be5a297cba6e61c8 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Wed, 11 Aug 2021 15:55:09 -1000 Subject: [PATCH 2/2] Lost some changes --- src/pages/home/ReportScreen.js | 65 ++++++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 14 deletions(-) diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index d411fb5d1cd..c0eaff54ca6 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -17,6 +17,7 @@ import KeyboardSpacer from '../../components/KeyboardSpacer'; import SwipeableView from '../../components/SwipeableView'; import CONST from '../../CONST'; import FullScreenLoadingIndicator from '../../components/FullscreenLoadingIndicator'; +import ReportActionPropTypes from './report/ReportActionPropTypes'; const propTypes = { /** Navigation route context info provided by react navigation */ @@ -35,6 +36,24 @@ const propTypes = { session: PropTypes.shape({ shouldShowComposeInput: PropTypes.bool, }), + + /** The report currently being looked at */ + report: PropTypes.shape({ + /** Number of actions unread */ + unreadActionCount: PropTypes.number, + + /** The largest sequenceNumber on this report */ + maxSequenceNumber: PropTypes.number, + + /** The current position of the new marker */ + newMarkerSequenceNumber: PropTypes.number, + + /** Whether there is an outstanding amount in IOU */ + hasOutstandingIOU: PropTypes.bool, + }), + + /** Array of report actions for this report */ + reportActions: PropTypes.objectOf(PropTypes.shape(ReportActionPropTypes)), }; const defaultProps = { @@ -42,8 +61,27 @@ const defaultProps = { session: { shouldShowComposeInput: true, }, + reportActions: {}, + report: { + unreadActionCount: 0, + maxSequenceNumber: 0, + hasOutstandingIOU: false, + }, }; +/** + * Get the currently viewed report ID as number + * + * @param {Object} route + * @param {Object} route.params + * @param {String} route.params.reportID + * @returns {Number} + */ +function getReportID(route) { + const params = route.params; + return Number.parseInt(params.reportID, 10); +} + class ReportScreen extends React.Component { constructor(props) { super(props); @@ -76,17 +114,7 @@ class ReportScreen extends React.Component { * @param {String} text */ onSubmitComment(text) { - addAction(this.getReportID(), text); - } - - /** - * Get the currently viewed report ID as number - * - * @returns {Number} - */ - getReportID() { - const params = this.props.route.params; - return Number.parseInt(params.reportID, 10); + addAction(getReportID(this.props.route), text); } /** @@ -95,7 +123,7 @@ class ReportScreen extends React.Component { * @returns {Boolean} */ shouldShowLoader() { - return this.state.isLoading || !this.getReportID(); + return this.state.isLoading || !getReportID(this.props.route); } /** @@ -111,7 +139,7 @@ class ReportScreen extends React.Component { * Persists the currently viewed report id */ storeCurrentlyViewedReport() { - const reportID = this.getReportID(); + const reportID = getReportID(this.props.route); if (_.isNaN(reportID)) { handleInaccessibleReport(); return; @@ -124,7 +152,7 @@ class ReportScreen extends React.Component { return null; } - const reportID = this.getReportID(); + const reportID = getReportID(this.props.route); return ( )} @@ -167,4 +197,11 @@ export default withOnyx({ session: { key: ONYXKEYS.SESSION, }, + reportActions: { + key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${getReportID(route)}`, + canEvict: false, + }, + report: { + key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${getReportID(route)}`, + }, })(ReportScreen);