Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate ReportFooter.js to function component #20182

Merged
merged 5 commits into from
Jun 7, 2023
Merged
Changes from 2 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
83 changes: 43 additions & 40 deletions src/pages/home/report/ReportFooter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, {useMemo} from 'react';
import _ from 'underscore';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
Expand Down Expand Up @@ -57,53 +57,56 @@ const defaultProps = {
shouldDisableCompose: false,
};

class ReportFooter extends React.Component {
function ReportFooter(props) {
/**
* @returns {Object}
*/
getChatFooterStyles() {
return {...styles.chatFooter, minHeight: !this.props.isOffline ? CONST.CHAT_FOOTER_MIN_HEIGHT : 0};
}
const getChatFooterStyles = useMemo(
dhairyasenjaliya marked this conversation as resolved.
Show resolved Hide resolved
() => ({
...styles.chatFooter,
minHeight: !props.isOffline ? CONST.CHAT_FOOTER_MIN_HEIGHT : 0,
}),
[props.isOffline],
);

render() {
const isArchivedRoom = ReportUtils.isArchivedRoom(this.props.report);
const isAllowedToComment = ReportUtils.isAllowedToComment(this.props.report);
const hideComposer = isArchivedRoom || !_.isEmpty(this.props.errors) || !isAllowedToComment;
const isArchivedRoom = useMemo(() => ReportUtils.isArchivedRoom(props.report), [props.report]);
const isAllowedToComment = useMemo(() => ReportUtils.isAllowedToComment(props.report), [props.report]);
const hideComposer = useMemo(() => isArchivedRoom || !_.isEmpty(props.errors) || !isAllowedToComment, [isArchivedRoom, props.errors, isAllowedToComment]);
dhairyasenjaliya marked this conversation as resolved.
Show resolved Hide resolved

return (
<>
{(isArchivedRoom || hideComposer) && (
<View style={[styles.chatFooter, this.props.isSmallScreenWidth ? styles.mb5 : null]}>
{isArchivedRoom && <ArchivedReportFooter report={this.props.report} />}
{!this.props.isSmallScreenWidth && (
<View style={styles.offlineIndicatorRow}>{hideComposer && <OfflineIndicator containerStyles={[styles.chatItemComposeSecondaryRow]} />}</View>
return (
<>
{(isArchivedRoom || hideComposer) && (
<View style={[styles.chatFooter, props.isSmallScreenWidth ? styles.mb5 : null]}>
{isArchivedRoom && <ArchivedReportFooter report={props.report} />}
{!props.isSmallScreenWidth && (
<View style={styles.offlineIndicatorRow}>{hideComposer && <OfflineIndicator containerStyles={[styles.chatItemComposeSecondaryRow]} />}</View>
)}
</View>
)}
{!hideComposer && (props.shouldShowComposeInput || !props.isSmallScreenWidth) && (
<View style={[getChatFooterStyles, props.isComposerFullSize && styles.chatFooterFullCompose]}>
<SwipeableView onSwipeDown={Keyboard.dismiss}>
{Session.isAnonymousUser() ? (
<AnonymousReportFooter report={props.report} />
) : (
<ReportActionCompose
onSubmit={props.onSubmitComment}
reportID={props.report.reportID.toString()}
reportActions={props.reportActions}
report={props.report}
pendingAction={props.pendingAction}
isComposerFullSize={props.isComposerFullSize}
disabled={props.shouldDisableCompose}
/>
)}
</View>
)}
{!hideComposer && (this.props.shouldShowComposeInput || !this.props.isSmallScreenWidth) && (
<View style={[this.getChatFooterStyles(), this.props.isComposerFullSize && styles.chatFooterFullCompose]}>
<SwipeableView onSwipeDown={Keyboard.dismiss}>
{Session.isAnonymousUser() ? (
<AnonymousReportFooter report={this.props.report} />
) : (
<ReportActionCompose
onSubmit={this.props.onSubmitComment}
reportID={this.props.report.reportID.toString()}
reportActions={this.props.reportActions}
report={this.props.report}
pendingAction={this.props.pendingAction}
isComposerFullSize={this.props.isComposerFullSize}
disabled={this.props.shouldDisableCompose}
/>
)}
</SwipeableView>
</View>
)}
</>
);
}
</SwipeableView>
</View>
)}
</>
);
}

ReportFooter.displayName = 'ReportFooter';
ReportFooter.propTypes = propTypes;
ReportFooter.defaultProps = defaultProps;
export default compose(
Expand Down