mirror of
https://github.com/luxfi/explore.git
synced 2026-09-24 00:28:18 +00:00
* add global setting to change between local and utc time * add control to change time format on detailed views * tweaks * adapt uptime graphs to work with utc time from settings * fix tests * add maxDiffPixels for SearchResults test * fix test
52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
import { chakra } from '@chakra-ui/react';
|
|
import React from 'react';
|
|
|
|
import type { TimeFormat } from 'types/settings';
|
|
|
|
import { useSettingsContext } from 'lib/contexts/settings';
|
|
import dayjs from 'lib/date/dayjs';
|
|
import useTimeAgoIncrement from 'lib/hooks/useTimeAgoIncrement';
|
|
import { Skeleton } from 'toolkit/chakra/skeleton';
|
|
import { Tooltip } from 'toolkit/chakra/tooltip';
|
|
|
|
type Props = {
|
|
timestamp?: string | number | null;
|
|
fallbackText?: string;
|
|
isLoading?: boolean;
|
|
enableIncrement?: boolean;
|
|
className?: string;
|
|
timeFormat?: TimeFormat;
|
|
};
|
|
|
|
const TimeWithTooltip = ({ timestamp, fallbackText, isLoading, enableIncrement, className, timeFormat: timeFormatProp }: Props) => {
|
|
|
|
const settings = useSettingsContext();
|
|
const timeFormat = timeFormatProp || settings?.timeFormat || 'relative';
|
|
const timeAgo = useTimeAgoIncrement(timestamp || '', enableIncrement && !isLoading && timeFormat === 'relative');
|
|
|
|
if (!timestamp && !fallbackText) {
|
|
return null;
|
|
}
|
|
|
|
const content = (() => {
|
|
if (!timestamp) {
|
|
return fallbackText;
|
|
}
|
|
|
|
if (timeFormat === 'relative') {
|
|
const content = settings?.isLocalTime ? dayjs(timestamp).format('llll') : dayjs(timestamp).utc().format('llll');
|
|
return <Tooltip content={ content }><span>{ timeAgo }</span></Tooltip>;
|
|
}
|
|
|
|
return <Tooltip content={ timeAgo }><span>{ dayjs(timestamp).utc(settings?.isLocalTime).format('lll') }</span></Tooltip>;
|
|
})();
|
|
|
|
return (
|
|
<Skeleton loading={ isLoading } className={ className }>
|
|
{ content }
|
|
</Skeleton>
|
|
);
|
|
};
|
|
|
|
export default chakra(TimeWithTooltip);
|