Skip to content

Commit 196b838

Browse files
committed
refactor: extract duplicate computation code into hook
1 parent 0b79391 commit 196b838

3 files changed

Lines changed: 15 additions & 8 deletions

File tree

src/pages/inbox/report/ReportActionsList.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ import type * as OnyxTypes from '@src/types/onyx';
7272
import FloatingMessageCounter from './FloatingMessageCounter';
7373
import getInitialNumToRender from './getInitialNumReportActionsToRender';
7474
import getReportActionsListInitialNumToRender from './getReportActionsListInitialNumToRender';
75-
import {useReportActionActiveEdit} from './ReportActionEditMessageContext';
7675
import ReportActionsListHeader from './ReportActionsListHeader';
7776
import ReportActionsListItemRenderer from './ReportActionsListItemRenderer';
7877
import {getUnreadMarkerReportAction} from './shouldDisplayNewMarkerOnReportAction';
7978
import ShowPreviousMessagesButton from './ShowPreviousMessagesButton';
8079
import StaticReportActionsPreview from './StaticReportActionsPreview';
8180
import useReportActionsNewActionLiveTail from './useReportActionsNewActionLiveTail';
8281
import useReportUnreadMessageScrollTracking from './useReportUnreadMessageScrollTracking';
82+
import useShouldShowComposerForActiveEditDraft from './useShouldShowComposerForActiveEditDraft';
8383

8484
type ReportActionsListProps = {
8585
/** The report currently being looked at */
@@ -842,8 +842,7 @@ function ReportActionsList({
842842
() => [shouldUseNarrowLayout ? unreadMarkerReportActionID : undefined, isArchivedNonExpenseReport(report, isReportArchived), draftReportAction?.reportActionID, draftMessageHTML],
843843
[draftMessageHTML, draftReportAction?.reportActionID, unreadMarkerReportActionID, shouldUseNarrowLayout, report, isReportArchived],
844844
);
845-
const {editingReportActionID} = useReportActionActiveEdit();
846-
const shouldShowComposerForActiveEditDraft = shouldUseNarrowLayout && editingReportActionID !== null;
845+
const shouldShowComposerForActiveEditDraft = useShouldShowComposerForActiveEditDraft();
847846
const hideComposer = !canUserPerformWriteAction(report, isReportArchived) && !shouldShowComposerForActiveEditDraft;
848847
const shouldShowReportRecipientLocalTime = canShowReportRecipientLocalTime(personalDetailsList, report, currentUserAccountID) && !isComposerFullSize;
849848
const canShowHeader = isOffline || hasHeaderRendered.current;

src/pages/inbox/report/ReportFooter.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ import ONYXKEYS from '@src/ONYXKEYS';
3232
import {isLoadingInitialReportActionsSelector} from '@src/selectors/ReportMetaData';
3333
import type * as OnyxTypes from '@src/types/onyx';
3434
import ReportActionCompose from './ReportActionCompose/ReportActionCompose';
35-
import {useReportActionActiveEdit} from './ReportActionEditMessageContext';
3635
import SystemChatReportFooterMessage from './SystemChatReportFooterMessage';
36+
import useShouldShowComposerForActiveEditDraft from './useShouldShowComposerForActiveEditDraft';
3737

3838
const policyRoleSelector = (policy: OnyxEntry<OnyxTypes.Policy>) => policy?.role;
3939

@@ -78,10 +78,7 @@ function ReportFooter() {
7878
const canWriteInReport = canWriteInReportUtil(report);
7979
const isSystemChat = isSystemChatUtil(report);
8080
const isAdminsOnlyPostingRoom = isAdminsOnlyPostingRoomUtil(report);
81-
const {editingReportActionID} = useReportActionActiveEdit();
82-
83-
// Narrow-screen edits use the bottom composer (#90516); mount it when a draft exists even if posting is admin-only.
84-
const shouldShowComposerForActiveEditDraft = shouldUseNarrowLayout && editingReportActionID !== null;
81+
const shouldShowComposerForActiveEditDraft = useShouldShowComposerForActiveEditDraft();
8582

8683
if (!isCurrentReportLoadedFromOnyx || !report || !reportIDFromRoute) {
8784
return null;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import useResponsiveLayout from '@hooks/useResponsiveLayout';
2+
import {useReportActionActiveEdit} from './ReportActionEditMessageContext';
3+
4+
/** Narrow-screen edits use the bottom composer (#90516); mount it when a draft exists even if posting is admin-only. */
5+
function useShouldShowComposerForActiveEditDraft() {
6+
const {shouldUseNarrowLayout} = useResponsiveLayout();
7+
const {editingReportActionID} = useReportActionActiveEdit();
8+
return shouldUseNarrowLayout && editingReportActionID !== null;
9+
}
10+
11+
export default useShouldShowComposerForActiveEditDraft;

0 commit comments

Comments
 (0)