Skip to content
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
9 changes: 8 additions & 1 deletion src/hooks/useCurrentReportID.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import type {NavigationState} from '@react-navigation/native';
import React, {createContext, useCallback, useContext, useMemo, useState} from 'react';
import {useOnyx} from 'react-native-onyx';
import Navigation from '@libs/Navigation/Navigation';
import {getReportIDFromLink} from '@libs/ReportUtils';
import ONYXKEYS from '@src/ONYXKEYS';

type CurrentReportIDContextValue = {
updateCurrentReportID: (state: NavigationState) => void;
currentReportID: string | undefined;
currentReportIDFromPath: string | undefined;
};

type CurrentReportIDContextProviderProps = {
Expand All @@ -16,6 +20,8 @@ const CurrentReportIDContext = createContext<CurrentReportIDContextValue | null>

function CurrentReportIDContextProvider(props: CurrentReportIDContextProviderProps) {
const [currentReportID, setCurrentReportID] = useState<string | undefined>('');
const [lastVisitedPath] = useOnyx(ONYXKEYS.LAST_VISITED_PATH);
const lastAccessReportFromPath = getReportIDFromLink(lastVisitedPath ?? null);

/**
* This function is used to update the currentReportID
Expand Down Expand Up @@ -46,8 +52,9 @@ function CurrentReportIDContextProvider(props: CurrentReportIDContextProviderPro
(): CurrentReportIDContextValue => ({
updateCurrentReportID,
currentReportID,
currentReportIDFromPath: lastAccessReportFromPath || undefined,
}),
[updateCurrentReportID, currentReportID],
[updateCurrentReportID, currentReportID, lastAccessReportFromPath],
);

return <CurrentReportIDContext.Provider value={contextValue}>{props.children}</CurrentReportIDContext.Provider>;
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useReportIDs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function ReportIDsContextProvider({
const {shouldUseNarrowLayout} = useResponsiveLayout();
const {accountID} = useCurrentUserPersonalDetails();
const currentReportIDValue = useCurrentReportID();
const derivedCurrentReportID = currentReportIDForTests ?? currentReportIDValue?.currentReportID;
const derivedCurrentReportID = currentReportIDForTests ?? currentReportIDValue?.currentReportIDFromPath ?? currentReportIDValue?.currentReportID;
Copy link
Contributor

Choose a reason for hiding this comment

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

We removed currentReportIDFromPath in #73457 as the flicker or flashing is not observed anymore.

const {activeWorkspaceID} = useActiveWorkspace();

const policyMemberAccountIDs = useMemo(() => getPolicyEmployeeListByIdWithoutCurrentUser(policies, activeWorkspaceID, accountID), [policies, activeWorkspaceID, accountID]);
Expand Down