diff --git a/pkg/interface/src/views/apps/chat/components/ChatMessage.tsx b/pkg/interface/src/views/apps/chat/components/ChatMessage.tsx index 6252383dd..a0e3ad671 100644 --- a/pkg/interface/src/views/apps/chat/components/ChatMessage.tsx +++ b/pkg/interface/src/views/apps/chat/components/ChatMessage.tsx @@ -24,6 +24,7 @@ import RemoteContent from '~/views/components/RemoteContent'; import { Mention } from '~/views/components/MentionText'; import styled from 'styled-components'; import useLocalState from '~/logic/state/local'; +import Timestamp from '~/views/components/Timestamp'; export const DATESTAMP_FORMAT = '[~]YYYY.M.D'; @@ -125,9 +126,7 @@ export default class ChatMessage extends Component { renderSigil ? 'cf pl2 lh-copy' : 'items-top cf hide-child' } ${isPending ? 'o-40' : ''} ${className}`; - const timestamp = moment - .unix(msg['time-sent'] / 1000) - .format(renderSigil ? 'hh:mm a' : 'hh:mm'); + const timestamp = moment.unix(msg['time-sent'] / 1000); const reboundMeasure = (event) => { return measure(this.divRef.current); @@ -217,7 +216,6 @@ interface MessageProps { export const MessageWithSigil = (props) => { const { msg, - timestamp, contacts, association, associations, @@ -232,9 +230,7 @@ export const MessageWithSigil = (props) => { const dark = useLocalState((state) => state.dark); - const datestamp = moment - .unix(msg['time-sent'] / 1000) - .format(DATESTAMP_FORMAT); + const stamp = moment.unix(msg['time-sent'] / 1000); const contact = `~${msg.author}` in contacts ? contacts[`~${msg.author}`] : false; const showNickname = useShowNickname(contact); const shipName = showNickname ? contact.nickname : cite(msg.author); @@ -342,19 +338,7 @@ export const MessageWithSigil = (props) => { > {displayName} - - {timestamp} - - - {datestamp} - + {msg.contents.map((c, i) => ( @@ -397,19 +381,15 @@ export const MessageWithoutSigil = ({ const { hovering, bind } = useHovering(); return ( <> - - {timestamp} - + /> { const { unreadCount, unreadMsg, dismissUnread, onClick } = props; if (!unreadMsg || (unreadCount === 0)) { return null; } + + const stamp = moment.unix(unreadMsg.post['time-sent'] / 1000); let datestamp = moment.unix(unreadMsg.post['time-sent'] / 1000).format('YYYY.M.D'); const timestamp = moment.unix(unreadMsg.post['time-sent'] / 1000).format('HH:mm'); @@ -34,14 +38,9 @@ export const UnreadNotice = (props) => { borderRadius='1' border='1' borderColor='blue'> - + {unreadCount} new message{unreadCount > 1 ? 's' : ''} since{' '} - {datestamp && ( - <> - ~{datestamp} at{' '} - - )} - {timestamp} + {cite(author)} - - {moment(time).format("HH:mm")} - + } ) => ( @@ -60,7 +61,6 @@ export function Header(props: { ) )(authors); - const time = moment(props.time).format("HH:mm"); const groupTitle = props.associations.groups?.[props.group]?.metadata?.title; @@ -93,9 +93,7 @@ export function Header(props: { } - - {time} - + ); } diff --git a/pkg/interface/src/views/apps/publish/components/NoteNavigation.tsx b/pkg/interface/src/views/apps/publish/components/NoteNavigation.tsx index b3633df3f..48cfeb87e 100644 --- a/pkg/interface/src/views/apps/publish/components/NoteNavigation.tsx +++ b/pkg/interface/src/views/apps/publish/components/NoteNavigation.tsx @@ -5,6 +5,7 @@ import { Link } from "react-router-dom"; import { Graph, GraphNode } from "~/types"; import { getLatestRevision } from "~/logic/lib/publish"; import { BigInteger } from "big-integer"; +import Timestamp from "~/views/components/Timestamp"; function NavigationItem(props: { url: string; @@ -12,7 +13,6 @@ function NavigationItem(props: { date: number; prev?: boolean; }) { - const date = moment(props.date).fromNow(); return ( {props.title} - {date} + ); diff --git a/pkg/interface/src/views/components/Author.tsx b/pkg/interface/src/views/components/Author.tsx index 8428121e4..c3e02c43e 100644 --- a/pkg/interface/src/views/components/Author.tsx +++ b/pkg/interface/src/views/components/Author.tsx @@ -8,6 +8,7 @@ import { Sigil } from '~/logic/lib/sigil'; import { Group } from '~/types'; import GlobalApi from '~/logic/api/global'; import { useHistory } from 'react-router-dom'; +import Timestamp from './Timestamp'; interface AuthorProps { contacts: Contacts; @@ -31,7 +32,7 @@ export default function Author(props: AuthorProps) { const color = contact?.color ? `#${uxToHex(contact?.color)}` : '#000000'; const showNickname = useShowNickname(contact); const name = showNickname ? contact.nickname : cite(ship); - const dateFmt = moment(date).fromNow(); + const stamp = moment(date); const [showOverlay, setShowOverlay] = useState(false); @@ -82,9 +83,7 @@ export default function Author(props: AuthorProps) { > {name} - - {dateFmt} - + {props.children} ); diff --git a/pkg/interface/src/views/components/Timestamp.tsx b/pkg/interface/src/views/components/Timestamp.tsx new file mode 100644 index 000000000..8ae91336d --- /dev/null +++ b/pkg/interface/src/views/components/Timestamp.tsx @@ -0,0 +1,54 @@ +import moment, { Moment as MomentType } from 'moment'; +import React, { ReactElement } from 'react'; + +import { Box, BoxProps, Text } from '@tlon/indigo-react'; +import { useHovering } from '~/logic/lib/util'; + +export const DateFormat = 'YYYY.M.D'; +export const TimeFormat = 'HH:mm'; + +export type TimestampProps = BoxProps & { + stamp: MomentType; + date?: boolean; + time?: boolean; +} + +const Timestamp = (props: TimestampProps): ReactElement | null=> { + const { stamp, date, time, color, fontSize, ...rest } = { + time: true, color: 'gray', fontSize: 0, ...props + }; + if (!stamp) return null; + const { hovering, bind } = date === true + ? { hovering: true, bind: {} } + : useHovering(); + let datestamp = stamp.format(DateFormat); + if (stamp.format(DateFormat) === moment().format(DateFormat)) { + datestamp = 'Today'; + } else if (stamp.format(DateFormat) === moment().subtract(1, 'day').format(DateFormat)) { + datestamp = 'Yesterday'; + } + const timestamp = stamp.format(TimeFormat); + return ( + + {time && {timestamp}} + {date !== false && + {datestamp} + } + + ) +} + +export default Timestamp; \ No newline at end of file