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

Refactor ReportScreen to improve chat switching #4538

Merged
merged 1 commit into from
Aug 11, 2021
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
56 changes: 46 additions & 10 deletions src/pages/home/ReportScreen.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import React from 'react';
import {withOnyx} from 'react-native-onyx';
import PropTypes from 'prop-types';
import {Keyboard, View} from 'react-native';
import _ from 'underscore';
import styles from '../../styles/styles';
import ReportView from './report/ReportView';
import ScreenWrapper from '../../components/ScreenWrapper';
import HeaderView from './HeaderView';
import Navigation from '../../libs/Navigation/Navigation';
import ROUTES from '../../ROUTES';
import FullScreenLoadingIndicator from '../../components/FullscreenLoadingIndicator';
import {handleInaccessibleReport, updateCurrentlyViewedReportID} from '../../libs/actions/Report';
import {handleInaccessibleReport, updateCurrentlyViewedReportID, addAction} from '../../libs/actions/Report';
import ONYXKEYS from '../../ONYXKEYS';

import ReportActionsView from './report/ReportActionsView';
import ReportActionCompose from './report/ReportActionCompose';
import KeyboardSpacer from '../../components/KeyboardSpacer';
import SwipeableView from '../../components/SwipeableView';
import CONST from '../../CONST';
import FullScreenLoadingIndicator from '../../components/FullscreenLoadingIndicator';

const propTypes = {
/** Navigation route context info provided by react navigation */
route: PropTypes.shape({
Expand All @@ -24,16 +30,26 @@ const propTypes = {

/** Tells us if the sidebar has rendered */
isSidebarLoaded: PropTypes.bool,

/** Whether or not to show the Compose Input */
session: PropTypes.shape({
shouldShowComposeInput: PropTypes.bool,
Copy link
Contributor

@deetergp deetergp Aug 11, 2021

Choose a reason for hiding this comment

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

NAB: Why is this nested in session and not its own prop? Is it because we want to keep track if it in ONXY?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't remember if I did this or if someone else did. But I'm gonna guess it just seemed more convenient than creating a new key to track this.

}),
};

const defaultProps = {
isSidebarLoaded: false,
session: {
shouldShowComposeInput: true,
},
};

class ReportScreen extends React.Component {
constructor(props) {
super(props);

this.onSubmitComment = this.onSubmitComment.bind(this);

this.state = {
isLoading: true,
};
Expand All @@ -56,6 +72,13 @@ class ReportScreen extends React.Component {
clearTimeout(this.loadingTimerId);
}

/**
* @param {String} text
*/
onSubmitComment(text) {
addAction(this.getReportID(), text);
}

/**
* Get the currently viewed report ID as number
*
Expand All @@ -76,13 +99,12 @@ class ReportScreen extends React.Component {
}

/**
* Configures a small loading transition of fixed time and proceeds with rendering available data
* Configures a small loading transition and proceeds with rendering available data
*/
prepareTransition() {
this.setState({isLoading: true});

clearTimeout(this.loadingTimerId);
this.loadingTimerId = setTimeout(() => this.setState({isLoading: false}), 150);
this.loadingTimerId = setTimeout(() => this.setState({isLoading: false}), 0);
}

/**
Expand All @@ -102,16 +124,27 @@ class ReportScreen extends React.Component {
return null;
}

const reportID = this.getReportID();
return (
<ScreenWrapper style={[styles.appContent, styles.flex1]}>
<HeaderView
reportID={this.getReportID()}
reportID={reportID}
onNavigationMenuButtonClicked={() => Navigation.navigate(ROUTES.HOME)}
/>

<FullScreenLoadingIndicator visible={this.shouldShowLoader()} />

{!this.shouldShowLoader() && <ReportView reportID={this.getReportID()} />}
<View nativeID={CONST.REPORT.DROP_NATIVE_ID} style={[styles.flex1, styles.justifyContentEnd]}>
<FullScreenLoadingIndicator visible={this.shouldShowLoader()} />
{!this.shouldShowLoader() && <ReportActionsView reportID={reportID} />}
{this.props.session.shouldShowComposeInput && (
<SwipeableView onSwipeDown={() => Keyboard.dismiss()}>
<ReportActionCompose
onSubmit={this.onSubmitComment}
reportID={reportID}
/>
</SwipeableView>
)}
<KeyboardSpacer />
</View>
</ScreenWrapper>
);
}
Expand All @@ -124,4 +157,7 @@ export default withOnyx({
isSidebarLoaded: {
key: ONYXKEYS.IS_SIDEBAR_LOADED,
},
session: {
key: ONYXKEYS.SESSION,
},
})(ReportScreen);
56 changes: 0 additions & 56 deletions src/pages/home/report/ReportView.js

This file was deleted.