diff --git a/apps/web/src/app/[orgShortcode]/convo/[convoId]/_components/messages-panel.tsx b/apps/web/src/app/[orgShortcode]/convo/[convoId]/_components/messages-panel.tsx index a39eb82e..431b2d0a 100644 --- a/apps/web/src/app/[orgShortcode]/convo/[convoId]/_components/messages-panel.tsx +++ b/apps/web/src/app/[orgShortcode]/convo/[convoId]/_components/messages-panel.tsx @@ -21,6 +21,7 @@ import { TooltipContent } from '@/src/components/shadcn-ui/tooltip'; import { type JSONContent, generateHTML } from '@u22n/tiptap/react'; +import { SmartDateTime } from '@/src/components/smart-date-time'; import { emailIdentityAtom, replyToMessageAtom } from '../atoms'; import { Virtuoso, type VirtuosoHandle } from 'react-virtuoso'; import { OriginalMessageView } from './original-message-view'; @@ -28,7 +29,6 @@ import { type RouterOutputs, platform } from '@/src/lib/trpc'; import { createExtensionSet } from '@u22n/tiptap/extensions'; import { useOrgShortcode } from '@/src/hooks/use-params'; import { type formatParticipantData } from '../../utils'; -import { useTimeAgo } from '@/src/hooks/use-time-ago'; import { cn, copyToClipboard } from '@/src/lib/utils'; import { Avatar } from '@/src/components/avatar'; import { type TypeId } from '@u22n/utils/typeid'; @@ -239,7 +239,6 @@ const MessageItem = memo( // if the message timestamp is less than a day ago, show the date instead of the time const isRecent = new Date().getTime() - message.createdAt.getTime() < ms('1 day'); - const timeAgo = useTimeAgo(message.createdAt); const viaAddress = message.metadata?.email?.from?.[0]?.email; @@ -328,7 +327,7 @@ const MessageItem = memo(
{isRecent ? ( - {timeAgo} + ) : (
{ return ( convo.participants.find( @@ -164,7 +162,7 @@ export const ConvoItem = memo(function ConvoItem({ {convo.subjects[0]?.subject} - {timeAgo} +
@@ -174,7 +172,7 @@ export const ConvoItem = memo(function ConvoItem({
- {authorAvatarData?.name.trim() ?? ' ' + ': '} + {(authorAvatarData?.name.trim() ?? '') + ': '} {convo.entries[0]?.bodyPlainText.trim() ?? ''} diff --git a/apps/web/src/components/smart-date-time.tsx b/apps/web/src/components/smart-date-time.tsx new file mode 100644 index 00000000..46793326 --- /dev/null +++ b/apps/web/src/components/smart-date-time.tsx @@ -0,0 +1,23 @@ +import { Tooltip, TooltipContent, TooltipTrigger } from './shadcn-ui/tooltip'; +import { useTimeAgo } from '../hooks/use-time-ago'; +import { ms } from '@u22n/utils/ms'; + +export function SmartDateTime({ + date, + relativeUntil = ms('1 day') +}: { + date: Date; + relativeUntil?: number; +}) { + const timeAgo = useTimeAgo(date); + const showRealDate = date.getTime() - Date.now() > relativeUntil; + + return ( + + + {showRealDate ? date.toLocaleDateString() : timeAgo} + + {date.toLocaleString()} + + ); +}