openreplay/frontend/app/components/shared/SessionItem/Counter.tsx
Andrey Babushkin fd5c0c9747
Add lokalisation (#3092)
* applied eslint

* add locales and lint the project

* removed error boundary

* updated locales

* fix min files

* fix locales
2025-03-06 17:43:15 +01:00

31 lines
855 B
TypeScript

import React, { useState, useEffect } from 'react';
import { Duration } from 'luxon';
import { durationFormatted, convertTimestampToUtcTimestamp } from 'App/date';
interface Props {
startTime: any;
className?: string;
}
function Counter({ startTime, className }: Props) {
let intervalId: NodeJS.Timer;
const [duration, setDuration] = useState(
convertTimestampToUtcTimestamp(new Date().getTime()) -
convertTimestampToUtcTimestamp(startTime),
);
const formattedDuration = durationFormatted(Duration.fromMillis(duration));
useEffect(() => {
if (!intervalId) {
intervalId = setInterval(() => {
setDuration(duration + 1000);
}, 1000);
}
return () => clearInterval(intervalId);
}, [duration]);
return <div className={className}>{startTime && formattedDuration}</div>;
}
export default Counter;