mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-21 08:11:24 +02:00
Fix duration tag
Closes: https://feedback.yaak.app/p/elapsed-time-not-stopping-on-failed-request
This commit is contained in:
@@ -6,23 +6,25 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function HttpResponseDurationTag({ response }: Props) {
|
export function HttpResponseDurationTag({ response }: Props) {
|
||||||
const [fallbackDuration, setFallbackDuration] = useState<number>(0);
|
const [fallbackElapsed, setFallbackElapsed] = useState<number>(0);
|
||||||
const timeout = useRef<NodeJS.Timeout>();
|
const timeout = useRef<NodeJS.Timeout>();
|
||||||
|
|
||||||
// Calculate the duration of the response for use when the response hasn't finished yet
|
// Calculate the duration of the response for use when the response hasn't finished yet
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
clearInterval(timeout.current);
|
clearInterval(timeout.current);
|
||||||
timeout.current = setInterval(() => {
|
timeout.current = setInterval(() => {
|
||||||
setFallbackDuration(Date.now() - new Date(response.createdAt + 'Z').getTime());
|
setFallbackElapsed(Date.now() - new Date(response.createdAt + 'Z').getTime());
|
||||||
}, 100);
|
}, 100);
|
||||||
return () => clearInterval(timeout.current);
|
return () => clearInterval(timeout.current);
|
||||||
}, [response.createdAt, response.elapsed, response.state]);
|
}, [response.createdAt, response.elapsed, response.state]);
|
||||||
|
|
||||||
const title = `HEADER: ${formatMillis(response.elapsedHeaders)}\nTOTAL: ${formatMillis(response.elapsed)}`;
|
const title = `HEADER: ${formatMillis(response.elapsedHeaders)}\nTOTAL: ${formatMillis(response.elapsed)}`;
|
||||||
|
|
||||||
|
const elapsed = response.state === 'closed' ? response.elapsed : fallbackElapsed;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span className="font-mono" title={title}>
|
<span className="font-mono" title={title}>
|
||||||
{formatMillis(response.elapsed || fallbackDuration)}
|
{formatMillis(elapsed)}
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user