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: regression 23735 #24619

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 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
20 changes: 5 additions & 15 deletions src/pages/home/sidebar/SidebarLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import React from 'react';
import {View} from 'react-native';
import _ from 'underscore';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import styles from '../../../styles/styles';
import * as StyleUtils from '../../../styles/StyleUtils';
import ONYXKEYS from '../../../ONYXKEYS';
Expand Down Expand Up @@ -37,7 +36,6 @@ import KeyboardShortcut from '../../../libs/KeyboardShortcut';
import onyxSubscribe from '../../../libs/onyxSubscribe';
import personalDetailsPropType from '../../personalDetailsPropType';
import * as ReportActionContextMenu from '../report/ContextMenu/ReportActionContextMenu';
import withCurrentReportID from '../../../components/withCurrentReportID';
import OptionRowLHNData from '../../../components/LHNOptionsList/OptionRowLHNData';

const basePropTypes = {
Expand Down Expand Up @@ -177,6 +175,8 @@ class SidebarLinks extends React.PureComponent {
render() {
const viewMode = this.props.priorityMode === CONST.PRIORITY_MODE.GSD ? CONST.OPTION_MODE.COMPACT : CONST.OPTION_MODE.DEFAULT;

const firstAccessReportID = this.props.optionListItems.includes(this.props.firstAccessReportID) ? this.props.firstAccessReportID : '';

return (
<View style={[styles.flex1, styles.h100]}>
<View
Expand Down Expand Up @@ -230,9 +230,9 @@ class SidebarLinks extends React.PureComponent {
</View>
{this.props.isLoading ? (
<>
{lodashGet(this.props.report, 'reportID') && (
{firstAccessReportID && (
<OptionRowLHNData
reportID={this.props.currentReportID}
reportID={firstAccessReportID}
viewMode={viewMode}
shouldDisableFocusOptions={this.props.isSmallScreenWidth}
onSelectRow={this.showReportPage}
Expand All @@ -256,15 +256,5 @@ class SidebarLinks extends React.PureComponent {

SidebarLinks.propTypes = propTypes;
SidebarLinks.defaultProps = defaultProps;
export default compose(
withLocalize,
withCurrentUserPersonalDetails,
withWindowDimensions,
withCurrentReportID,
withOnyx({
report: {
key: ({currentReportID}) => `${ONYXKEYS.COLLECTION.REPORT}${currentReportID}`,
},
}),
)(SidebarLinks);
export default compose(withLocalize, withCurrentUserPersonalDetails, withWindowDimensions)(SidebarLinks);
export {basePropTypes};
16 changes: 13 additions & 3 deletions src/pages/home/sidebar/SidebarLinksData.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useMemo, useRef} from 'react';
import React, {useEffect, useMemo, useRef, useState} from 'react';
import _ from 'underscore';
import {deepEqual} from 'fast-equals';
import {withOnyx} from 'react-native-onyx';
Expand Down Expand Up @@ -66,7 +66,11 @@ const defaultProps = {
function SidebarLinksData({isFocused, allReportActions, betas, chatReports, currentReportID, insets, isLoadingReportData, isSmallScreenWidth, onLinkClick, policies, priorityMode}) {
const {translate} = useLocalize();

const [isFirstTimeReportLoading, setIsFirstTimeReportLoading] = useState(SessionUtils.didUserLogInDuringSession());

const reportIDsRef = useRef([]);
const firstAccessReportID = useRef(currentReportID);

const optionListItems = useMemo(() => {
const reportIDs = SidebarUtils.getOrderedReportIDs(currentReportID, chatReports, betas, policies, priorityMode, allReportActions);
if (deepEqual(reportIDsRef.current, reportIDs)) {
Expand All @@ -76,7 +80,12 @@ function SidebarLinksData({isFocused, allReportActions, betas, chatReports, curr
return reportIDs;
}, [allReportActions, betas, chatReports, currentReportID, policies, priorityMode]);

const isLoading = SessionUtils.didUserLogInDuringSession() && isLoadingReportData;
useEffect(() => {
if (!isFirstTimeReportLoading) {
return;
}
setIsFirstTimeReportLoading(isLoadingReportData);
}, [isFirstTimeReportLoading, isLoadingReportData]);
Copy link
Contributor

Choose a reason for hiding this comment

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

The code is not very intuitive about:

  • Why do we initialize isFirstTimeReportLoading using SessionUtils.didUserLogInDuringSession()
  • Why do we need/use isFirstTimeReportLoading instead of isLoadingReportData

Would be good to add some comments, on why we are doing things like we are here.

I also have to get familiarized with SessionUtils.didUserLogInDuringSession() as I'm not what does this state represent and why does it matter for the LHN


return (
<View
Expand All @@ -91,8 +100,9 @@ function SidebarLinksData({isFocused, allReportActions, betas, chatReports, curr
isSmallScreenWidth={isSmallScreenWidth}
priorityMode={priorityMode}
// Data props:
isLoading={isLoading}
isLoading={isFirstTimeReportLoading}
optionListItems={optionListItems}
firstAccessReportID={firstAccessReportID.current}
/>
</View>
);
Expand Down