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

fix: show existing reports while loading #25159

Merged
merged 19 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 9 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
9 changes: 7 additions & 2 deletions src/components/LHNOptionsList/LHNOptionsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import OptionRowLHNData from './OptionRowLHNData';
import variables from '../../styles/variables';

const propTypes = {
/** Wrapper style for the section list */
// eslint-disable-next-line react/forbid-prop-types
style: PropTypes.arrayOf(PropTypes.object),

/** Extra styles for the section list container */
// eslint-disable-next-line react/forbid-prop-types
contentContainerStyles: PropTypes.arrayOf(PropTypes.object).isRequired,
Expand All @@ -26,10 +30,11 @@ const propTypes = {
};

const defaultProps = {
style: [styles.flex1],
Copy link
Contributor

Choose a reason for hiding this comment

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

you can just use style: {styles.flex1}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

shouldDisableFocusOptions: false,
};

function LHNOptionsList({contentContainerStyles, data, onSelectRow, optionMode, shouldDisableFocusOptions}) {
function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optionMode, shouldDisableFocusOptions}) {
/**
* This function is used to compute the layout of any given item in our list. Since we know that each item will have the exact same height, this is a performance optimization
* so that the heights can be determined before the options are rendered. Otherwise, the heights are determined when each option is rendering and it causes a lot of overhead on large
Expand Down Expand Up @@ -67,7 +72,7 @@ function LHNOptionsList({contentContainerStyles, data, onSelectRow, optionMode,
);

return (
<View style={[styles.flex1]}>
<View style={style}>
<FlatList
indicatorStyle="white"
keyboardShouldPersistTaps="always"
Expand Down
33 changes: 10 additions & 23 deletions src/pages/home/sidebar/SidebarLinks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable rulesdir/onyx-props-must-have-default */
import lodashGet from 'lodash/get';
import React from 'react';
import {View} from 'react-native';
import _ from 'underscore';
Expand Down Expand Up @@ -32,7 +31,6 @@ import KeyboardShortcut from '../../../libs/KeyboardShortcut';
import onyxSubscribe from '../../../libs/onyxSubscribe';
import * as ReportActionContextMenu from '../report/ContextMenu/ReportActionContextMenu';
import withCurrentReportID from '../../../components/withCurrentReportID';
import OptionRowLHNData from '../../../components/LHNOptionsList/OptionRowLHNData';
import SignInOrAvatarWithOptionalStatus from './SignInOrAvatarWithOptionalStatus';

const basePropTypes = {
Expand Down Expand Up @@ -186,27 +184,16 @@ class SidebarLinks extends React.PureComponent {
</Tooltip>
<SignInOrAvatarWithOptionalStatus isCreateMenuOpen={this.props.isCreateMenuOpen} />
</View>
{this.props.isLoading ? (
<>
{lodashGet(this.props.report, 'reportID') && (
<OptionRowLHNData
reportID={this.props.currentReportID}
viewMode={viewMode}
shouldDisableFocusOptions={this.props.isSmallScreenWidth}
onSelectRow={this.showReportPage}
/>
)}
<OptionsListSkeletonView shouldAnimate />
</>
) : (
<LHNOptionsList
contentContainerStyles={[styles.sidebarListContainer, {paddingBottom: StyleUtils.getSafeAreaMargins(this.props.insets).marginBottom}]}
data={this.props.optionListItems}
onSelectRow={this.showReportPage}
shouldDisableFocusOptions={this.props.isSmallScreenWidth}
optionMode={viewMode}
/>
)}

<LHNOptionsList
style={[this.props.isLoading ? styles.flexShrink1 : styles.flex1]}
contentContainerStyles={[styles.sidebarListContainer, {paddingBottom: StyleUtils.getSafeAreaMargins(this.props.insets).marginBottom}]}
data={this.props.optionListItems}
onSelectRow={this.showReportPage}
shouldDisableFocusOptions={this.props.isSmallScreenWidth}
optionMode={viewMode}
/>
{this.props.isLoading && <OptionsListSkeletonView shouldAnimate />}
</View>
);
}
Expand Down
16 changes: 10 additions & 6 deletions src/pages/home/sidebar/SidebarLinksData.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,21 @@ const defaultProps = {
function SidebarLinksData({isFocused, allReportActions, betas, chatReports, currentReportID, insets, isLoadingReportData, isSmallScreenWidth, onLinkClick, policies, priorityMode}) {
const {translate} = useLocalize();

const reportIDsRef = useRef([]);
const reportIDsRef = useRef(null);
const isLoading = SessionUtils.didUserLogInDuringSession() && isLoadingReportData;
const optionListItems = useMemo(() => {
const reportIDs = SidebarUtils.getOrderedReportIDs(currentReportID, chatReports, betas, policies, priorityMode, allReportActions);
if (deepEqual(reportIDsRef.current, reportIDs)) {
return reportIDsRef.current;
}
reportIDsRef.current = reportIDs;
return reportIDs;
}, [allReportActions, betas, chatReports, currentReportID, policies, priorityMode]);

const isLoading = SessionUtils.didUserLogInDuringSession() && isLoadingReportData;
if (isLoading && !reportIDsRef.current && !currentReportID) {
reportIDsRef.current = reportIDs;
}
if (!isLoading) {
Copy link
Contributor

Choose a reason for hiding this comment

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

i think you can move this to 78 line too like if (long condition || !isLoading)

reportIDsRef.current = reportIDs;
}
return reportIDsRef.current || [];
}, [allReportActions, betas, chatReports, currentReportID, policies, priorityMode, isLoading]);
Copy link
Contributor

Choose a reason for hiding this comment

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

@s-alves10 can you add some comments trying to say why we using this ref and notes on each of the cases you have there?

It is just not very easy to understand why we have this complexity

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comments added


return (
<View
Expand Down
Loading