/* eslint-disable i18next/no-literal-string */ import React from 'react'; import { numberWithCommas } from 'App/utils'; import styles from './loadInfo.module.css'; import { useTranslation } from 'react-i18next'; function LoadInfo({ webvitals, event: { fcpTime, visuallyComplete, timeToInteractive }, prorata: { a, b, c }, }) { const { t } = useTranslation(); return (
{typeof fcpTime === 'number' &&
} {typeof visuallyComplete === 'number' && (
)} {typeof timeToInteractive === 'number' && (
)}
{typeof fcpTime === 'number' && (
{t('Time to Render')}
{`${numberWithCommas(fcpTime || 0)}${t('ms')}`}
)} {typeof visuallyComplete === 'number' && (
{t('Visually Complete')}
{`${numberWithCommas(visuallyComplete || 0)}${t('ms')}`}
)} {typeof timeToInteractive === 'number' && (
{t('Time To Interactive')}
{`${numberWithCommas(timeToInteractive || 0)}${t('ms')}`}
)} {webvitals ? Object.keys(webvitals).map((key) => ( )) : null}
); } function WebVitalsValue({ name, value }) { const valInt = Number(value); const valDisplay = name !== 'CLS' ? Math.round(valInt) : valInt > 1 ? Math.round(valInt) : valInt.toExponential(1).split('e'); const unit = { CLS: 'score', FCP: 'ms', INP: 'ms', LCP: 'ms', TTFB: 'ms', }; return (
{name}
{Array.isArray(valDisplay) ? ( <> {valDisplay[0]} × 10 {valDisplay[1]} ) : ( <> {valDisplay} {unit[name]} )}
); } const WebVitalsValueMemo = React.memo(WebVitalsValue); LoadInfo.displayName = 'LoadInfo'; export default React.memo(LoadInfo);