mirror of
https://github.com/hanzonet/explore.git
synced 2026-10-30 18:16:57 +00:00
* cookie for storing time format value * rename TimeAgo component * add toggle to tables (pt. 1) * move TimeWithTooltip component * add toggle to tables (pt. 2) * change implementation of toggle component * remove unnecessary timestamp label * update screenshots * more screenshot updates * [skip ci] update clock icon * update screenshots
51 lines
1.5 KiB
TypeScript
51 lines
1.5 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') {
|
|
return <Tooltip content={ dayjs(timestamp).format('llll') }><span>{ timeAgo }</span></Tooltip>;
|
|
}
|
|
|
|
return <Tooltip content={ timeAgo }><span>{ dayjs(timestamp).format('lll') }</span></Tooltip>;
|
|
})();
|
|
|
|
return (
|
|
<Skeleton loading={ isLoading } className={ className }>
|
|
{ content }
|
|
</Skeleton>
|
|
);
|
|
};
|
|
|
|
export default chakra(TimeWithTooltip);
|