-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor report footer and move shouldShowComposeInput out of ReportS…
…creen
- Loading branch information
Showing
10 changed files
with
166 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import Onyx from 'react-native-onyx'; | ||
import ONYXKEYS from '../../ONYXKEYS'; | ||
|
||
/** | ||
* @param {Boolean} shouldShowComposeInput | ||
*/ | ||
function setShouldShowComposeInput(shouldShowComposeInput) { | ||
Onyx.set(ONYXKEYS.SHOULD_SHOW_COMPOSE_INPUT, shouldShowComposeInput); | ||
} | ||
|
||
export { | ||
// eslint-disable-next-line import/prefer-default-export | ||
setShouldShowComposeInput, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import * as Session from '../actions/Session'; | ||
import * as Composer from '../actions/Composer'; | ||
|
||
export default (shouldShowComposeInput, isSmallScreenWidth = true) => { | ||
if (!isSmallScreenWidth) { | ||
return; | ||
} | ||
|
||
Session.setShouldShowComposeInput(shouldShowComposeInput); | ||
Composer.setShouldShowComposeInput(shouldShowComposeInput); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import * as Session from '../actions/Session'; | ||
import * as Composer from '../actions/Composer'; | ||
|
||
export default shouldShowComposeInput => Session.setShouldShowComposeInput(shouldShowComposeInput); | ||
export default shouldShowComposeInput => Composer.setShouldShowComposeInput(shouldShowComposeInput); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import React from 'react'; | ||
import _ from 'underscore'; | ||
import PropTypes from 'prop-types'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import {View, Keyboard} from 'react-native'; | ||
import lodashFindLast from 'lodash/findLast'; | ||
|
||
import CONST from '../../../CONST'; | ||
import ReportActionCompose from './ReportActionCompose'; | ||
import * as ReportUtils from '../../../libs/ReportUtils'; | ||
import SwipeableView from '../../../components/SwipeableView'; | ||
import OfflineIndicator from '../../../components/OfflineIndicator'; | ||
import OfflineWithFeedback from '../../../components/OfflineWithFeedback'; | ||
import ArchivedReportFooter from '../../../components/ArchivedReportFooter'; | ||
import compose from '../../../libs/compose'; | ||
import ONYXKEYS from '../../../ONYXKEYS'; | ||
import withWindowDimensions, {windowDimensionsPropTypes} from '../../../components/withWindowDimensions'; | ||
import styles from '../../../styles/styles'; | ||
import reportActionPropTypes from './reportActionPropTypes'; | ||
import reportPropTypes from './reportPropTypes'; | ||
|
||
const propTypes = { | ||
/** Report object for the current report */ | ||
report: reportPropTypes.isRequired, | ||
|
||
/** Report actions for the current report */ | ||
reportActions: reportActionPropTypes.isRequired, | ||
|
||
/** Offline status */ | ||
isOffline: PropTypes.bool.isRequired, | ||
|
||
/** Any errors associated with an attempt to create a workspace room */ | ||
// eslint-disable-next-line react/forbid-prop-types | ||
addWorkspaceRoomErrors: PropTypes.object, | ||
|
||
/** The pending action when we are adding a workspace room */ | ||
addWorkspaceRoomPendingAction: PropTypes.string, | ||
|
||
/** Whether the composer input should be shown */ | ||
shouldShowComposeInput: PropTypes.bool, | ||
|
||
...windowDimensionsPropTypes, | ||
}; | ||
|
||
const defaultProps = { | ||
shouldShowComposeInput: true, | ||
addWorkspaceRoomErrors: {}, | ||
addWorkspaceRoomPendingAction: '', | ||
}; | ||
|
||
class ReportFooter extends React.Component { | ||
/** | ||
* @returns {Object} | ||
*/ | ||
getChatFooterStyles() { | ||
return {...styles.chatFooter, minHeight: !this.props.isOffline ? CONST.CHAT_FOOTER_MIN_HEIGHT : 0}; | ||
} | ||
|
||
render() { | ||
const isArchivedRoom = ReportUtils.isArchivedRoom(this.props.report); | ||
let reportClosedAction; | ||
if (isArchivedRoom) { | ||
reportClosedAction = lodashFindLast(this.props.reportActions, action => action.actionName === CONST.REPORT.ACTIONS.TYPE.CLOSED); | ||
} | ||
const hideComposer = isArchivedRoom || !_.isEmpty(this.props.addWorkspaceRoomErrors); | ||
return ( | ||
<> | ||
{(isArchivedRoom || hideComposer) && ( | ||
<View style={[styles.chatFooter]}> | ||
{isArchivedRoom && ( | ||
<ArchivedReportFooter | ||
reportClosedAction={reportClosedAction} | ||
report={this.props.report} | ||
/> | ||
)} | ||
{!this.props.isSmallScreenWidth && ( | ||
<View style={styles.offlineIndicatorRow}> | ||
{hideComposer && ( | ||
<OfflineIndicator containerStyles={[styles.chatItemComposeSecondaryRow]} /> | ||
)} | ||
</View> | ||
)} | ||
</View> | ||
)} | ||
{(!hideComposer && this.props.shouldShowComposeInput) && ( | ||
<View style={[this.getChatFooterStyles(), this.props.isComposerFullSize && styles.chatFooterFullCompose]}> | ||
<SwipeableView onSwipeDown={Keyboard.dismiss}> | ||
<OfflineWithFeedback | ||
pendingAction={this.props.addWorkspaceRoomPendingAction} | ||
> | ||
<ReportActionCompose | ||
onSubmit={this.props.onSubmitComment} | ||
reportID={this.props.report.reportID} | ||
reportActions={this.props.reportActions} | ||
report={this.props.report} | ||
isComposerFullSize={this.props.isComposerFullSize} | ||
/> | ||
</OfflineWithFeedback> | ||
</SwipeableView> | ||
</View> | ||
)} | ||
</> | ||
); | ||
} | ||
} | ||
|
||
ReportFooter.propTypes = propTypes; | ||
ReportFooter.defaultProps = defaultProps; | ||
export default compose( | ||
withWindowDimensions, | ||
withOnyx({ | ||
shouldShowComposeInput: {key: ONYXKEYS.SHOULD_SHOW_COMPOSE_INPUT}, | ||
}), | ||
)(ReportFooter); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import PropTypes from 'prop-types'; | ||
|
||
export default PropTypes.shape({ | ||
/** The largest sequenceNumber on this report */ | ||
maxSequenceNumber: PropTypes.number, | ||
|
||
/** Whether there is an outstanding amount in IOU */ | ||
hasOutstandingIOU: PropTypes.bool, | ||
|
||
/** Flag to check if the report actions data are loading */ | ||
isLoadingReportActions: PropTypes.bool, | ||
|
||
/** ID for the report */ | ||
reportID: PropTypes.number, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters