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
8 changes: 8 additions & 0 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,13 @@ const CONST = {
MAX_IMAGE_PIXEL_COUNT: 50000000,
CHUNK_LOAD_ERROR: 'ChunkLoadError',

CHRONOS: {
TIMER_COMMAND: {
START: 'start',
STOP: 'stop',
},
},

RECEIPT_CAMERA: {
PHOTO_WIDTH: 4032,
PHOTO_HEIGHT: 3024,
Expand Down Expand Up @@ -8692,6 +8699,7 @@ const CONST = {
},
HEADER_VIEW: {
BACK_BUTTON: 'HeaderView-BackButton',
CHRONOS_TIMER_BUTTON: 'HeaderView-ChronosTimerButton',
DETAILS_BUTTON: 'HeaderView-DetailsButton',
},
SEARCH: {
Expand Down
79 changes: 79 additions & 0 deletions src/components/ChronosTimerHeaderButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import React from 'react';
import {View} from 'react-native';
import type {OnyxEntry, OnyxKey} from 'react-native-onyx';
import useAncestors from '@hooks/useAncestors';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useIsInSidePanel from '@hooks/useIsInSidePanel';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import useReportIsArchived from '@hooks/useReportIsArchived';
import useThemeStyles from '@hooks/useThemeStyles';
import {isChronosTimerRunningFromVisibleActions} from '@libs/ChronosUtils';
import {getSortedReportActionsForDisplay} from '@libs/ReportActionsUtils';
import {canUserPerformWriteAction, canWriteInReport} from '@libs/ReportUtils';
import {addComment} from '@userActions/Report';
import {callFunctionIfActionIsAllowed} from '@userActions/Session';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type * as OnyxTypes from '@src/types/onyx';
import type {ReportActions} from '@src/types/onyx/ReportAction';
import Button from './Button';

type ChronosTimerHeaderButtonProps = {
report: OnyxTypes.Report;
Comment thread
roryabraham marked this conversation as resolved.
Resolved
};

function ChronosTimerHeaderButton({report}: ChronosTimerHeaderButtonProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const isReportArchived = useReportIsArchived(report?.reportID);
const canPerformWriteAction = canUserPerformWriteAction(report, isReportArchived);
const [visibleReportActionsData] = useOnyx(ONYXKEYS.DERIVED.VISIBLE_REPORT_ACTIONS);

const {accountID: currentUserAccountID, timezone: timezoneParam} = useCurrentUserPersonalDetails();
const reportActionsOnyxKey = `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}` as OnyxKey;
const [isTimerRunning] = useOnyx<OnyxKey, boolean>(
reportActionsOnyxKey,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

❌ PERF-11 (docs)

The useOnyx selector on REPORT_ACTIONS returns a full ReportAction[] array via getSortedReportActionsForDisplay. Onyx runs deepEqual on the selector output to decide whether to re-render, and comparing an entire array of report actions is expensive. Additionally, the selector closes over visibleReportActionsData (the entire VISIBLE_REPORT_ACTIONS for ALL reports), meaning any change to visible actions in ANY report triggers re-execution of this expensive selector.

The component only needs to know whether the timer is running (a boolean). Compute the final boolean directly in the selector instead of returning the full array:

const [isTimerRunning] = useOnyx<OnyxKey, boolean>(
    reportActionsOnyxKey,
    {
        selector: (reportActions: unknown): boolean => {
            const sorted = getSortedReportActionsForDisplay(
                reportActions as OnyxEntry<ReportActions>,
                canPerformWriteAction,
                false,
                visibleReportActionsData,
                report.reportID,
            );
            return isChronosTimerRunningFromVisibleActions(sorted, currentUserAccountID);
        },
    },
    [canPerformWriteAction, visibleReportActionsData, report.reportID, currentUserAccountID],
);

This reduces deepEqual to a trivial boolean comparison and eliminates the intermediate array allocation.


Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

{
selector: (reportActions: unknown): boolean => {
const sorted = getSortedReportActionsForDisplay(reportActions as OnyxEntry<ReportActions>, canPerformWriteAction, false, visibleReportActionsData, report.reportID);
return isChronosTimerRunningFromVisibleActions(sorted, currentUserAccountID);
},
},
[canPerformWriteAction, visibleReportActionsData, report.reportID, currentUserAccountID],
);

const ancestors = useAncestors(report);
const isInSidePanel = useIsInSidePanel();

function sendCommentToChronos() {
addComment({
report,
notifyReportID: report.reportID,
ancestors,
text: isTimerRunning ? CONST.CHRONOS.TIMER_COMMAND.STOP : CONST.CHRONOS.TIMER_COMMAND.START,
timezoneParam: timezoneParam ?? CONST.DEFAULT_TIME_ZONE,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

❌ CONSISTENCY-2 (docs)

The literal strings 'stop' and 'start' are timer command strings sent as chat messages and also matched by the regexes in ReportActionsUtils.ts. These are domain-specific command values that should be defined as named constants to avoid typos and maintain a single source of truth.

Define constants in CONST, for example:

// In CONST
CHRONOS: {
    TIMER_COMMAND: {
        START: 'start',
        STOP: 'stop',
    },
},

Then use them in the component:

text: isTimerRunning ? CONST.CHRONOS.TIMER_COMMAND.STOP : CONST.CHRONOS.TIMER_COMMAND.START,

And in ReportActionsUtils.ts for comparing return values:

return getLatestUserChronosTimerCommand(...) === CONST.CHRONOS.TIMER_COMMAND.START;

Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

currentUserAccountID,
shouldPlaySound: false,
isInSidePanel,
});
}

if (!canWriteInReport(report)) {
return null;
}

return (
<View style={[styles.flexRow, styles.alignItemsCenter, styles.justifyContentEnd]}>
<Button
success={!isTimerRunning}
text={translate(isTimerRunning ? 'chronos.stopTimer' : 'chronos.startTimer')}
onPress={callFunctionIfActionIsAllowed(sendCommentToChronos)}
style={styles.flex1}
sentryLabel={CONST.SENTRY_LABEL.HEADER_VIEW.CHRONOS_TIMER_BUTTON}
/>
</View>
);
}

export default ChronosTimerHeaderButton;
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import useWindowDimensions from '@hooks/useWindowDimensions';
import {dismissRejectUseExplanation} from '@libs/actions/IOU';
import {queueExportSearchWithTemplate} from '@libs/actions/Search';
import {isConsecutiveChronosAutomaticTimerAction} from '@libs/ChronosUtils';
import DateUtils from '@libs/DateUtils';
import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID';
import {isActionVisibleOnMoneyRequestReport} from '@libs/MoneyRequestReportUtils';
Expand All @@ -51,7 +52,6 @@
getMostRecentIOURequestActionID,
getOneTransactionThreadReportID,
hasNextActionMadeBySameActor,
isConsecutiveChronosAutomaticTimerAction,
isCurrentActionUnread,
isDeletedParentAction,
isIOUActionMatchingTransactionList,
Expand Down Expand Up @@ -769,7 +769,7 @@
if (didLayout.current) {
return;
}

Check warning on line 772 in src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

React Hook useCallback has a duplicate dependency: 'isOffline'. Either omit it or remove the dependency array

Check warning on line 772 in src/components/MoneyRequestReportView/MoneyRequestReportActionsList.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

React Hook useCallback has a duplicate dependency: 'isOffline'. Either omit it or remove the dependency array
didLayout.current = true;

markOpenReportEnd(report, {warm: !shouldShowOpenReportLoadingSkeleton});
Expand Down
2 changes: 2 additions & 0 deletions src/languages/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7697,6 +7697,8 @@ Fordern Sie Spesendetails wie Belege und Beschreibungen an, legen Sie Limits und
chronos: {
oooEventSummaryFullDay: (summary: string, dayCount: number, date: string) => `${summary} für ${dayCount} ${dayCount === 1 ? 'Tag' : 'Tage'} bis ${date}`,
oooEventSummaryPartialDay: (summary: string, timePeriod: string, date: string) => `${summary} von ${timePeriod} am ${date}`,
startTimer: 'Timer starten',
stopTimer: 'Timer stoppen',
},
footer: {
features: 'Funktionen',
Expand Down
2 changes: 2 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7679,6 +7679,8 @@ const translations = {
chronos: {
oooEventSummaryFullDay: (summary: string, dayCount: number, date: string) => `${summary} for ${dayCount} ${dayCount === 1 ? 'day' : 'days'} until ${date}`,
oooEventSummaryPartialDay: (summary: string, timePeriod: string, date: string) => `${summary} from ${timePeriod} on ${date}`,
startTimer: 'Start Timer',
stopTimer: 'Stop Timer',
},
footer: {
features: 'Features',
Expand Down
2 changes: 2 additions & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7575,6 +7575,8 @@ ${amount} para ${merchant} - ${date}`,
chronos: {
oooEventSummaryFullDay: (summary, dayCount, date) => `${summary} por ${dayCount} ${dayCount === 1 ? 'día' : 'días'} hasta el ${date}`,
oooEventSummaryPartialDay: (summary, timePeriod, date) => `${summary} de ${timePeriod} del ${date}`,
startTimer: 'Iniciar temporizador',
stopTimer: 'Detener temporizador',
},
footer: {
features: 'Características',
Expand Down
2 changes: 2 additions & 0 deletions src/languages/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7720,6 +7720,8 @@ Rendez obligatoires des informations de dépense comme les reçus et les descrip
chronos: {
oooEventSummaryFullDay: (summary: string, dayCount: number, date: string) => `${summary} pour ${dayCount} ${dayCount === 1 ? 'jour' : 'jours'} jusqu’au ${date}`,
oooEventSummaryPartialDay: (summary: string, timePeriod: string, date: string) => `${summary} du ${timePeriod} le ${date}`,
startTimer: 'Démarrer le minuteur',
stopTimer: 'Arrêter le minuteur',
},
footer: {
features: 'Fonctionnalités',
Expand Down
2 changes: 2 additions & 0 deletions src/languages/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7684,6 +7684,8 @@ Richiedi dettagli sulle spese come ricevute e descrizioni, imposta limiti e valo
chronos: {
oooEventSummaryFullDay: (summary: string, dayCount: number, date: string) => `${summary} per ${dayCount} ${dayCount === 1 ? 'giorno' : 'giorni'} fino al ${date}`,
oooEventSummaryPartialDay: (summary: string, timePeriod: string, date: string) => `${summary} dal ${timePeriod} del ${date}`,
startTimer: 'Avvia timer',
stopTimer: 'Ferma timer',
},
footer: {
features: 'Funzionalità',
Expand Down
2 changes: 2 additions & 0 deletions src/languages/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7589,6 +7589,8 @@ ${reportName}
chronos: {
oooEventSummaryFullDay: (summary: string, dayCount: number, date: string) => `${summary}(${date} までの ${dayCount} ${dayCount === 1 ? '日' : '日数'} 分)`,
oooEventSummaryPartialDay: (summary: string, timePeriod: string, date: string) => `${date}の${timePeriod}の${summary}`,
startTimer: 'タイマー開始',
stopTimer: 'タイマーを停止',
},
footer: {
features: '機能',
Expand Down
2 changes: 2 additions & 0 deletions src/languages/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7663,6 +7663,8 @@ Vereis onkostendetails zoals bonnen en beschrijvingen, stel limieten en standaar
chronos: {
oooEventSummaryFullDay: (summary: string, dayCount: number, date: string) => `${summary} voor ${dayCount} ${dayCount === 1 ? 'dag' : 'dagen'} tot ${date}`,
oooEventSummaryPartialDay: (summary: string, timePeriod: string, date: string) => `${summary} van ${timePeriod} op ${date}`,
startTimer: 'Timer starten',
stopTimer: 'Timer stoppen',
},
footer: {
features: 'Functies',
Expand Down
2 changes: 2 additions & 0 deletions src/languages/pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7649,6 +7649,8 @@ Wymagaj szczegółów wydatków, takich jak paragony i opisy, ustawiaj limity i
chronos: {
oooEventSummaryFullDay: (summary: string, dayCount: number, date: string) => `${summary} za ${dayCount} ${dayCount === 1 ? 'dzień' : 'dni'} do ${date}`,
oooEventSummaryPartialDay: (summary: string, timePeriod: string, date: string) => `${summary} z ${timePeriod} z dnia ${date}`,
startTimer: 'Startuj licznik',
stopTimer: 'Zatrzymaj licznik czasu',
},
footer: {
features: 'Funkcje',
Expand Down
2 changes: 2 additions & 0 deletions src/languages/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7653,6 +7653,8 @@ Exija dados de despesas como recibos e descrições, defina limites e padrões e
chronos: {
oooEventSummaryFullDay: (summary: string, dayCount: number, date: string) => `${summary} por ${dayCount} ${dayCount === 1 ? 'dia' : 'dias'} até ${date}`,
oooEventSummaryPartialDay: (summary: string, timePeriod: string, date: string) => `${summary} de ${timePeriod} em ${date}`,
startTimer: 'Iniciar cronômetro',
stopTimer: 'Parar cronômetro',
},
footer: {
features: 'Recursos',
Expand Down
2 changes: 2 additions & 0 deletions src/languages/zh-hans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7458,6 +7458,8 @@ ${reportName}
chronos: {
oooEventSummaryFullDay: (summary: string, dayCount: number, date: string) => `${summary},共计 ${dayCount} ${dayCount === 1 ? '天' : '天'},截至 ${date}`,
oooEventSummaryPartialDay: (summary: string, timePeriod: string, date: string) => `${summary},时间范围:${timePeriod},日期:${date}`,
startTimer: '开始计时',
stopTimer: '停止计时器',
},
footer: {
features: '功能',
Expand Down
94 changes: 94 additions & 0 deletions src/libs/ChronosUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import type {OnyxEntry, OnyxInputOrEntry} from 'react-native-onyx';

Check failure on line 1 in src/libs/ChronosUtils.ts

View workflow job for this annotation

GitHub Actions / typecheck

Module '"react-native-onyx"' has no exported member 'OnyxInputOrEntry'. Did you mean to use 'import OnyxInputOrEntry from "react-native-onyx"' instead?
import type {ValueOf} from 'type-fest';
import CONST from '@src/CONST';
import type ReportAction from '@src/types/onyx/ReportAction';
import {getReportActionText} from './ReportActionsUtils';

type GetReportActionTextArg = Parameters<typeof getReportActionText>[0];

/**
* Next visible report action after `actionIndex` in a newest-first list (same behavior as `findPreviousAction` in ReportActionsUtils).
*/
function findPreviousVisibleReportAction(reportActions: ReportAction[], actionIndex: number, isOffline: boolean): OnyxEntry<ReportAction> {
for (let i = actionIndex + 1; i < reportActions.length; i++) {
const action = reportActions.at(i);

if (!isOffline && action?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE) {
continue;
}

if (action?.shouldShow === false) {
continue;
}

return action;
}

return undefined;
}

function isChronosOOOListAction(reportAction: OnyxInputOrEntry<ReportAction>): reportAction is ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.CHRONOS_OOO_LIST> {
const action = reportAction as {actionName?: string} | null | undefined;
return action?.actionName === CONST.REPORT.ACTIONS.TYPE.CHRONOS_OOO_LIST;
}

// The entire trimmed message must be a timer command (not a word embedded in normal chat). Case-insensitive.
// "at ..." is only allowed after past-tense "started"/"stopped" so phrases like "stop at the corner" do not match.
const CHRONOS_TIMER_COMMAND_STOP_REGEX = /^(?:stop(?:ping)?(?:\s+now)?|stopped(?:\s+now)?(?:\s+at\b.*)?)$/i;
const CHRONOS_TIMER_COMMAND_START_REGEX = /^(?:start(?:ing)?(?:\s+now)?|started(?:\s+now)?(?:\s+at\b.*)?)$/i;

type ChronosTimerCommandValue = ValueOf<typeof CONST.CHRONOS.TIMER_COMMAND>;

/**
* Returns `CONST.CHRONOS.TIMER_COMMAND.START`, `CONST.CHRONOS.TIMER_COMMAND.STOP`, or `null` when the trimmed text is only a Chronos timer command (e.g. "start", "stop now", "started at …", "stopped at …"), not when "start"/"stop" appear inside a sentence.
*/
function isChronosStartOrStopMessage(text: string): ChronosTimerCommandValue | null {
const trimmedText = text.trim();
if (CHRONOS_TIMER_COMMAND_STOP_REGEX.test(trimmedText)) {
return CONST.CHRONOS.TIMER_COMMAND.STOP;
}
if (CHRONOS_TIMER_COMMAND_START_REGEX.test(trimmedText)) {
return CONST.CHRONOS.TIMER_COMMAND.START;
}
return null;
}

function isChronosAutomaticTimerAction(reportAction: OnyxInputOrEntry<ReportAction>, isChronosReport: boolean): boolean {
return isChronosReport && isChronosStartOrStopMessage(getReportActionText(reportAction as GetReportActionTextArg)) !== null;
}

/**
* From visible report actions sorted newest-first, returns the latest ADD_COMMENT from the current user that looks like a Chronos timer command.
*/
function getLatestUserChronosTimerCommand(sortedVisibleReportActionsDesc: ReportAction[], currentUserAccountID: number): ChronosTimerCommandValue | null {
for (const action of sortedVisibleReportActionsDesc) {
if (action.actionName !== CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT) {
continue;
}
if (action.actorAccountID !== currentUserAccountID) {
continue;
}
const kind = isChronosStartOrStopMessage(getReportActionText(action as GetReportActionTextArg));
if (kind !== null) {
return kind;
}
}
return null;
}

function isChronosTimerRunningFromVisibleActions(sortedVisibleReportActionsDesc: ReportAction[], currentUserAccountID: number): boolean {
return getLatestUserChronosTimerCommand(sortedVisibleReportActionsDesc, currentUserAccountID) === CONST.CHRONOS.TIMER_COMMAND.START;
}

/**
* If the user sends consecutive actions to Chronos to automatically start/stop the timer,
* then detect that and show each individually so that the user can easily see when they were sent.
*/
function isConsecutiveChronosAutomaticTimerAction(reportActions: ReportAction[], actionIndex: number, isChronosReport: boolean, isOffline: boolean): boolean {
const previousAction = findPreviousVisibleReportAction(reportActions, actionIndex, isOffline);
const currentAction = reportActions?.at(actionIndex);
return isChronosAutomaticTimerAction(currentAction, isChronosReport) && isChronosAutomaticTimerAction(previousAction, isChronosReport);
}

export type {ChronosTimerCommandValue};
export {getLatestUserChronosTimerCommand, isChronosOOOListAction, isChronosStartOrStopMessage, isChronosTimerRunningFromVisibleActions, isConsecutiveChronosAutomaticTimerAction};
21 changes: 0 additions & 21 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
}

let allReportActions: OnyxCollection<ReportActions>;
Onyx.connect({

Check warning on line 92 in src/libs/ReportActionsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand All @@ -101,7 +101,7 @@
});

let allReports: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 104 in src/libs/ReportActionsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -110,13 +110,13 @@
});

let deprecatedIsNetworkOffline = false;
Onyx.connect({

Check warning on line 113 in src/libs/ReportActionsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NETWORK,
callback: (val) => (deprecatedIsNetworkOffline = val?.isOffline ?? false),
});

let deprecatedCurrentUserAccountID: number | undefined;
Onyx.connect({

Check warning on line 119 in src/libs/ReportActionsUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
// When signed out, value is undefined
Expand Down Expand Up @@ -391,10 +391,6 @@
return reportAction?.actionName ? POLICY_CHANGE_LOG_ARRAY.has(reportAction.actionName) : false;
}

function isChronosOOOListAction(reportAction: OnyxInputOrEntry<ReportAction>): reportAction is ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.CHRONOS_OOO_LIST> {
return isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.CHRONOS_OOO_LIST);
}

function isAddCommentAction(reportAction: OnyxInputOrEntry<ReportAction>): reportAction is ReportAction<typeof CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT> {
return isActionOfType(reportAction, CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT);
}
Expand Down Expand Up @@ -985,21 +981,6 @@

return currentActionActorAccountID === adjacentActionActorAccountID;
}
function isChronosAutomaticTimerAction(reportAction: OnyxInputOrEntry<ReportAction>, isChronosReport: boolean): boolean {
const isAutomaticStartTimerAction = () => /start(?:ed|ing)?(?:\snow)?/i.test(getReportActionText(reportAction));
const isAutomaticStopTimerAction = () => /stop(?:ped|ping)?(?:\snow)?/i.test(getReportActionText(reportAction));
return isChronosReport && (isAutomaticStartTimerAction() || isAutomaticStopTimerAction());
}

/**
* If the user sends consecutive actions to Chronos to automatically start/stop the timer,
* then detect that and show each individually so that the user can easily see when they were sent.
*/
function isConsecutiveChronosAutomaticTimerAction(reportActions: ReportAction[], actionIndex: number, isChronosReport: boolean, isOffline: boolean): boolean {
const previousAction = findPreviousAction(reportActions, actionIndex, isOffline);
const currentAction = reportActions?.at(actionIndex);
return isChronosAutomaticTimerAction(currentAction, isChronosReport) && isChronosAutomaticTimerAction(previousAction, isChronosReport);
}

/**
* Checks if a reportAction is deprecated.
Expand Down Expand Up @@ -4607,10 +4588,8 @@
isApprovedOrSubmittedReportAction,
isIOURequestReportAction,
isNewerReportAction,
isChronosOOOListAction,
isClosedAction,
isConsecutiveActionMadeByPreviousActor,
isConsecutiveChronosAutomaticTimerAction,
isExportedToIntegrationAction,
hasNextActionMadeBySameActor,
isCreatedAction,
Expand Down
10 changes: 10 additions & 0 deletions src/pages/inbox/HeaderView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import React, {useMemo} from 'react';
import {View} from 'react-native';
import Button from '@components/Button';
import CaretWrapper from '@components/CaretWrapper';
import ChronosTimerHeaderButton from '@components/ChronosTimerHeaderButton';
import DisplayNames from '@components/DisplayNames';
import HeaderLoadingBar from '@components/HeaderLoadingBar';
import Icon from '@components/Icon';
Expand Down Expand Up @@ -41,6 +42,7 @@ import {getReportName} from '@libs/ReportNameUtils';
import {
canJoinChat,
canUserPerformWriteAction,
chatIncludesChronos,
getChatRoomSubtitle,
getDisplayNamesWithTooltips,
getParentNavigationSubtitle,
Expand Down Expand Up @@ -384,6 +386,7 @@ function HeaderView({onNavigationMenuButtonClicked, reportID}: HeaderViewProps)
success={!hasActiveScheduledCall}
/>
)}
{!shouldUseNarrowLayout && chatIncludesChronos(report) && <ChronosTimerHeaderButton report={report} />}
{!shouldUseNarrowLayout && isOpenTaskReport(report, parentReportAction) && <TaskHeaderActionButton report={report} />}
{!isParentReportLoading && canJoin && !shouldUseNarrowLayout && joinButton}
</View>
Expand Down Expand Up @@ -423,6 +426,13 @@ function HeaderView({onNavigationMenuButtonClicked, reportID}: HeaderViewProps)
/>
)}
</View>
{!!report && shouldUseNarrowLayout && chatIncludesChronos(report) && (
<View style={[styles.appBG, styles.pl0]}>
<View style={[styles.ph5, styles.pb3]}>
<ChronosTimerHeaderButton report={report} />
</View>
</View>
)}
{!!report && shouldUseNarrowLayout && isOpenTaskReport(report, parentReportAction) && (
<View style={[styles.appBG, styles.pl0]}>
<View style={[styles.ph5, styles.pb3]}>
Expand Down
Loading
Loading