Skip to content
Merged
9 changes: 1 addition & 8 deletions src/hooks/useCurrentReportID.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import type {NavigationState} from '@react-navigation/native';
import React, {createContext, useCallback, useContext, useMemo, useState} from 'react';
import Navigation from '@libs/Navigation/Navigation';
import {getReportIDFromLink} from '@libs/ReportUtils';
import ONYXKEYS from '@src/ONYXKEYS';
import useOnyx from './useOnyx';

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

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

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

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

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

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