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
22 changes: 11 additions & 11 deletions src/pages/Search/SearchMoneyRequestReportPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavig
import type {SearchFullscreenNavigatorParamList} from '@libs/Navigation/types';
import {isValidReportIDFromPath} from '@libs/ReportUtils';
import Navigation from '@navigation/Navigation';
import ReactionListWrapper from '@pages/home/ReactionListWrapper';
import variables from '@styles/variables';
import {openReport} from '@userActions/Report';
import ONYXKEYS from '@src/ONYXKEYS';
import {ActionListContext, ReactionListContext} from '@src/pages/home/ReportScreenContext';
import type {ActionListContextType, ReactionListRef, ScrollPosition} from '@src/pages/home/ReportScreenContext';
import {ActionListContext} from '@src/pages/home/ReportScreenContext';
import type {ActionListContextType, ScrollPosition} from '@src/pages/home/ReportScreenContext';
import type SCREENS from '@src/SCREENS';
import SearchTypeMenu from './SearchTypeMenu';

Expand All @@ -47,17 +48,16 @@ function SearchMoneyRequestReportPage({route}: SearchMoneyRequestPageProps) {
const {canUseLeftHandBar} = usePermissions();

const reportIDFromRoute = getNonEmptyStringOnyxID(route.params?.reportID);
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportIDFromRoute}`, {allowStaleData: true});
const [reportMetadata = defaultReportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportIDFromRoute}`);
const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {allowStaleData: true, initialValue: {}});
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportIDFromRoute}`, {allowStaleData: true, canBeMissing: true});
const [reportMetadata = defaultReportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportIDFromRoute}`, {canBeMissing: true});
const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {allowStaleData: true, initialValue: {}, canBeMissing: false});
const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`];
const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP);
const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: true});

const {isEditingDisabled, isCurrentReportLoadedFromOnyx} = useIsReportReadyToDisplay(report, reportIDFromRoute);

const [scrollPosition, setScrollPosition] = useState<ScrollPosition>({});
const flatListRef = useRef<FlatList>(null);
const reactionListRef = useRef<ReactionListRef>(null);
const actionListValue = useMemo((): ActionListContextType => ({flatListRef, scrollPosition, setScrollPosition}), [flatListRef, scrollPosition, setScrollPosition]);

const reportID = report?.reportID;
Expand Down Expand Up @@ -88,7 +88,7 @@ function SearchMoneyRequestReportPage({route}: SearchMoneyRequestPageProps) {
if (shouldUseNarrowLayout) {
return (
<ActionListContext.Provider value={actionListValue}>
<ReactionListContext.Provider value={reactionListRef}>
<ReactionListWrapper>
<ScreenWrapper
testID={SearchMoneyRequestReportPage.displayName}
shouldEnableMaxHeight
Expand All @@ -113,14 +113,14 @@ function SearchMoneyRequestReportPage({route}: SearchMoneyRequestPageProps) {
/>
</FullPageNotFoundView>
</ScreenWrapper>
</ReactionListContext.Provider>
</ReactionListWrapper>
</ActionListContext.Provider>
);
}

return (
<ActionListContext.Provider value={actionListValue}>
<ReactionListContext.Provider value={reactionListRef}>
<ReactionListWrapper>
<ScreenWrapper
testID={SearchMoneyRequestReportPage.displayName}
shouldEnableMaxHeight
Expand Down Expand Up @@ -166,7 +166,7 @@ function SearchMoneyRequestReportPage({route}: SearchMoneyRequestPageProps) {
</View>
</View>
</ScreenWrapper>
</ReactionListContext.Provider>
</ReactionListWrapper>
</ActionListContext.Provider>
);
}
Expand Down
16 changes: 16 additions & 0 deletions src/pages/home/ReactionListWrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React, {useRef} from 'react';
import PopoverReactionList from './report/ReactionList/PopoverReactionList';
import {ReactionListContext} from './ReportScreenContext';
import type {ReactionListRef} from './ReportScreenContext';

function ReactionListWrapper({children}: {children: React.ReactNode}) {
const reactionListRef = useRef<ReactionListRef>(null);
return (
<ReactionListContext.Provider value={reactionListRef}>
{children}
<PopoverReactionList ref={reactionListRef} />
</ReactionListContext.Provider>
);
}

export default ReactionListWrapper;
41 changes: 21 additions & 20 deletions src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,11 @@ import SCREENS from '@src/SCREENS';
import type * as OnyxTypes from '@src/types/onyx';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import HeaderView from './HeaderView';
import ReactionListWrapper from './ReactionListWrapper';
import ReportActionsView from './report/ReportActionsView';
import ReportFooter from './report/ReportFooter';
import type {ActionListContextType, ReactionListRef, ScrollPosition} from './ReportScreenContext';
import {ActionListContext, ReactionListContext} from './ReportScreenContext';
import type {ActionListContextType, ScrollPosition} from './ReportScreenContext';
import {ActionListContext} from './ReportScreenContext';

type ReportScreenNavigationProps = PlatformStackScreenProps<ReportsSplitNavigatorParamList, typeof SCREENS.REPORT>;

Expand Down Expand Up @@ -139,24 +140,24 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
const isSkippingOpenReport = useRef(false);
const flatListRef = useRef<FlatList>(null);
const {canUseDefaultRooms} = usePermissions();
const reactionListRef = useRef<ReactionListRef>(null);
const {isOffline} = useNetwork();
const {shouldUseNarrowLayout, isInNarrowPaneModal} = useResponsiveLayout();
const {activeWorkspaceID} = useActiveWorkspace();
const currentReportIDValue = useCurrentReportID();

const [modal] = useOnyx(ONYXKEYS.MODAL);
const [isComposerFullSize] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_IS_COMPOSER_FULL_SIZE}${reportIDFromRoute}`, {initialValue: false});
const [accountManagerReportID] = useOnyx(ONYXKEYS.ACCOUNT_MANAGER_REPORT_ID);
const [accountManagerReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(accountManagerReportID)}`);
const [userLeavingStatus] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_USER_IS_LEAVING_ROOM}${reportIDFromRoute}`, {initialValue: false});
const [reportOnyx] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportIDFromRoute}`, {allowStaleData: true});
const [reportNameValuePairsOnyx] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportIDFromRoute}`, {allowStaleData: true});
const [reportMetadata = defaultReportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportIDFromRoute}`);
const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {allowStaleData: true, initialValue: {}});
const [modal] = useOnyx(ONYXKEYS.MODAL, {canBeMissing: false});
const [isComposerFullSize] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_IS_COMPOSER_FULL_SIZE}${reportIDFromRoute}`, {initialValue: false, canBeMissing: true});
const [accountManagerReportID] = useOnyx(ONYXKEYS.ACCOUNT_MANAGER_REPORT_ID, {canBeMissing: true});
const [accountManagerReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(accountManagerReportID)}`, {canBeMissing: true});
const [userLeavingStatus] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_USER_IS_LEAVING_ROOM}${reportIDFromRoute}`, {initialValue: false, canBeMissing: true});
const [reportOnyx] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportIDFromRoute}`, {allowStaleData: true, canBeMissing: true});
const [reportNameValuePairsOnyx] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportIDFromRoute}`, {allowStaleData: true, canBeMissing: true});
const [reportMetadata = defaultReportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportIDFromRoute}`, {canBeMissing: true});
const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {allowStaleData: true, initialValue: {}, canBeMissing: false});
const [parentReportAction] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${getNonEmptyStringOnyxID(reportOnyx?.parentReportID)}`, {
canEvict: false,
selector: (parentReportActions) => getParentReportAction(parentReportActions, reportOnyx?.parentReportActionID),
canBeMissing: true,
});
const deletedParentAction = isDeletedParentAction(parentReportAction);
const prevDeletedParentAction = usePrevious(deletedParentAction);
Expand Down Expand Up @@ -186,7 +187,7 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
navigation.setParams({reportID: lastAccessedReportID});
}, [activeWorkspaceID, canUseDefaultRooms, navigation, route]);

const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST, {canBeMissing: true});
const chatWithAccountManagerText = useMemo(() => {
if (accountManagerReportID) {
const participants = getParticipantsAccountIDsForDisplay(accountManagerReport, false, true);
Expand Down Expand Up @@ -261,9 +262,9 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
const lastReportIDFromRoute = usePrevious(reportIDFromRoute);
const [isLinkingToMessage, setIsLinkingToMessage] = useState(!!reportActionIDFromRoute);

const [currentUserAccountID = -1] = useOnyx(ONYXKEYS.SESSION, {selector: (value) => value?.accountID});
const [currentUserEmail] = useOnyx(ONYXKEYS.SESSION, {selector: (value) => value?.email});
const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP);
const [currentUserAccountID = -1] = useOnyx(ONYXKEYS.SESSION, {selector: (value) => value?.accountID, canBeMissing: false});
const [currentUserEmail] = useOnyx(ONYXKEYS.SESSION, {selector: (value) => value?.email, canBeMissing: false});
const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: true});
const {reportActions, linkedAction, sortedAllReportActions, hasNewerActions, hasOlderActions} = usePaginatedReportActions(reportID, reportActionIDFromRoute);

const [isBannerVisible, setIsBannerVisible] = useState(true);
Expand Down Expand Up @@ -292,7 +293,7 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
const isLinkedMessagePageReady = isLinkedMessageAvailable && (reportActions.length - indexOfLinkedMessage >= CONST.REPORT.MIN_INITIAL_REPORT_ACTION_COUNT || doesCreatedActionExists());

const transactionThreadReportID = getOneTransactionThreadReportID(reportID, reportActions ?? [], isOffline);
const [transactionThreadReportActions = {}] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`);
const [transactionThreadReportActions = {}] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`, {canBeMissing: true});
const combinedReportActions = getCombinedReportActions(reportActions, transactionThreadReportID ?? null, Object.values(transactionThreadReportActions));
const lastReportAction = [...combinedReportActions, parentReportAction].find((action) => canEditReportAction(action) && !isMoneyRequestAction(action));
const isSingleTransactionView = isMoneyRequest(report) || isTrackExpenseReport(report);
Expand Down Expand Up @@ -386,7 +387,7 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
() => !!linkedAction && isWhisperAction(linkedAction) && !(linkedAction?.whisperedToAccountIDs ?? []).includes(currentUserAccountID),
[currentUserAccountID, linkedAction],
);
const [deleteTransactionNavigateBackUrl] = useOnyx(ONYXKEYS.NVP_DELETE_TRANSACTION_NAVIGATE_BACK_URL);
const [deleteTransactionNavigateBackUrl] = useOnyx(ONYXKEYS.NVP_DELETE_TRANSACTION_NAVIGATE_BACK_URL, {canBeMissing: true});

useEffect(() => {
if (!isFocused || !deleteTransactionNavigateBackUrl) {
Expand Down Expand Up @@ -720,7 +721,7 @@ function ReportScreen({route, navigation}: ReportScreenProps) {

return (
<ActionListContext.Provider value={actionListValue}>
<ReactionListContext.Provider value={reactionListRef}>
<ReactionListWrapper>
<ScreenWrapper
navigation={navigation}
style={screenWrapperStyle}
Expand Down Expand Up @@ -793,7 +794,7 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
</DragAndDropProvider>
</FullPageNotFoundView>
</ScreenWrapper>
</ReactionListContext.Provider>
</ReactionListWrapper>
</ActionListContext.Provider>
);
}
Expand Down
13 changes: 5 additions & 8 deletions src/pages/home/report/ReportActionsView.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {useIsFocused, useRoute} from '@react-navigation/native';
import React, {useCallback, useContext, useEffect, useMemo, useRef, useState} from 'react';
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
import {InteractionManager} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
Expand Down Expand Up @@ -29,13 +29,11 @@ import {
shouldReportActionBeVisible,
} from '@libs/ReportActionsUtils';
import {buildOptimisticCreatedReportAction, buildOptimisticIOUReportAction, canUserPerformWriteAction, isMoneyRequestReport} from '@libs/ReportUtils';
import {ReactionListContext} from '@pages/home/ReportScreenContext';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type SCREENS from '@src/SCREENS';
import type * as OnyxTypes from '@src/types/onyx';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import PopoverReactionList from './ReactionList/PopoverReactionList';
import ReportActionsList from './ReportActionsList';
import UserTypingEventListener from './UserTypingEventListener';

Expand Down Expand Up @@ -75,13 +73,13 @@ function ReportActionsView({
hasOlderActions,
}: ReportActionsViewProps) {
useCopySelectionHelper();
const reactionListRef = useContext(ReactionListContext);
const route = useRoute<PlatformStackRouteProp<ReportsSplitNavigatorParamList, typeof SCREENS.REPORT>>();
const [transactionThreadReportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID ?? CONST.DEFAULT_NUMBER_ID}`, {
const [transactionThreadReportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${transactionThreadReportID}`, {
selector: (reportActions: OnyxEntry<OnyxTypes.ReportActions>) => getSortedReportActionsForDisplay(reportActions, canUserPerformWriteAction(report), true),
canBeMissing: true,
});
const [transactionThreadReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID ?? CONST.DEFAULT_NUMBER_ID}`);
const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP);
const [transactionThreadReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`, {canBeMissing: true});
const [isLoadingApp] = useOnyx(ONYXKEYS.IS_LOADING_APP, {canBeMissing: true});
const prevTransactionThreadReport = usePrevious(transactionThreadReport);
const reportActionID = route?.params?.reportActionID;
const prevReportActionID = usePrevious(reportActionID);
Expand Down Expand Up @@ -303,7 +301,6 @@ function ReportActionsView({
shouldEnableAutoScrollToTopThreshold={shouldEnableAutoScroll}
/>
<UserTypingEventListener report={report} />
<PopoverReactionList ref={reactionListRef} />
</>
);
}
Expand Down