Skip to content

Commit 883b0e2

Browse files
commit
1 parent 454743d commit 883b0e2

4 files changed

Lines changed: 35 additions & 27 deletions

File tree

src/App/src/components/common/ProcessingStatusIndicator.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
11
import { Spinner } from '@fluentui/react-components';
2+
import { formatElapsedTime } from '@/utils';
23

34
interface ProcessingStatusIndicatorProps {
45
message: string;
56
elapsedSeconds?: number;
67
}
78

8-
const formatElapsedTime = (elapsedSeconds: number): string => {
9-
if (elapsedSeconds < 60) {
10-
return `${elapsedSeconds}s`;
11-
}
12-
13-
const minutes = Math.floor(elapsedSeconds / 60);
14-
const seconds = elapsedSeconds % 60;
15-
return `${minutes}min ${seconds}sec`;
16-
};
17-
189
const ProcessingStatusIndicator = ({
1910
message,
2011
elapsedSeconds,
2112
}: ProcessingStatusIndicatorProps) => {
22-
const showElapsedSuffix = Number.isFinite(elapsedSeconds) && (elapsedSeconds as number) > 0;
23-
const elapsedSuffix = showElapsedSuffix ? ` (${formatElapsedTime(elapsedSeconds as number)})` : '';
13+
const showElapsedSuffix = typeof elapsedSeconds === 'number' && elapsedSeconds > 0;
14+
const elapsedSuffix = showElapsedSuffix ? ` (${formatElapsedTime(elapsedSeconds)})` : '';
2415

2516
return (
2617
<div

src/App/src/hooks/usePlanWebSocket.tsx

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {
4646
} from '@/models';
4747
import { APIService } from '@/api/apiService';
4848
import { ToastIntent } from '@/components/toast/InlineToaster';
49+
import { formatElapsedTime } from '@/utils';
4950

5051
const apiService = new APIService();
5152

@@ -57,16 +58,6 @@ interface UsePlanWebSocketProps {
5758
showToast: (content: React.ReactNode, intent?: ToastIntent, options?: { dismissible?: boolean; timeoutMs?: number | null }) => number;
5859
}
5960

60-
const formatElapsedTime = (elapsedSeconds: number): string => {
61-
if (elapsedSeconds < 60) {
62-
return `${elapsedSeconds}s`;
63-
}
64-
65-
const minutes = Math.floor(elapsedSeconds / 60);
66-
const seconds = elapsedSeconds % 60;
67-
return `${minutes}min ${seconds}sec`;
68-
};
69-
7061
/**
7162
* Creates an AgentMessageResponse and persists it, then optionally reloads the task list.
7263
*/
@@ -115,8 +106,12 @@ export function usePlanWebSocket({
115106
const processingStartedAtRef = React.useRef<number | null>(null);
116107

117108
useEffect(() => {
118-
if (showProcessingPlanSpinner && processingStartedAtRef.current === null) {
119-
processingStartedAtRef.current = Date.now();
109+
if (showProcessingPlanSpinner) {
110+
if (processingStartedAtRef.current === null) {
111+
processingStartedAtRef.current = Date.now();
112+
}
113+
} else {
114+
processingStartedAtRef.current = null;
120115
}
121116
}, [showProcessingPlanSpinner]);
122117

@@ -282,7 +277,6 @@ export function usePlanWebSocket({
282277
};
283278
dispatch(addAgentMessage(errorAgent));
284279
dispatch(planFailedFinal());
285-
dispatch(setShowProcessingPlanSpinner(false));
286280
processingStartedAtRef.current = null;
287281
dispatch(setShowBufferingText(false));
288282
dispatch(setSubmittingChatDisableInput(true));

src/App/src/utils/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* - agentIconUtils → agent-to-icon mapping
99
*/
1010

11-
export { formatDate } from './utils';
11+
export { formatDate, formatElapsedTime } from './utils';
1212
export { getErrorMessage, getErrorStyle } from './errorUtils';
1313
export { formatErrorMessage, extractPlainAnswer, truncate } from './messageUtils';
1414
export {

src/App/src/utils/utils.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,27 @@ export const formatDate = (
6767
});
6868

6969
return formatted;
70-
}
70+
}
71+
72+
/**
73+
* Formats an elapsed-time duration in seconds for display in processing
74+
* indicators and completion messages.
75+
*
76+
* Examples:
77+
* - 5 → "5s"
78+
* - 59 → "59s"
79+
* - 60 → "1min 0sec"
80+
* - 75 → "1min 15sec"
81+
*
82+
* @param elapsedSeconds Non-negative integer seconds elapsed.
83+
* @returns Human-readable elapsed-time string.
84+
*/
85+
export const formatElapsedTime = (elapsedSeconds: number): string => {
86+
if (elapsedSeconds < 60) {
87+
return `${elapsedSeconds}s`;
88+
}
89+
90+
const minutes = Math.floor(elapsedSeconds / 60);
91+
const seconds = elapsedSeconds % 60;
92+
return `${minutes}min ${seconds}sec`;
93+
};

0 commit comments

Comments
 (0)