diff --git a/chat/package.json b/chat/package.json index b3244f7144..82cb297762 100644 --- a/chat/package.json +++ b/chat/package.json @@ -1,6 +1,6 @@ { "name": "chat", - "version": "0.0.10", + "version": "0.0.11", "main": "index.js", "license": "MIT", "dependencies": { diff --git a/chat/src/features/chat/ChatMessage.tsx b/chat/src/features/chat/ChatMessage.tsx index d3d532faaa..b22ece981c 100644 --- a/chat/src/features/chat/ChatMessage.tsx +++ b/chat/src/features/chat/ChatMessage.tsx @@ -7,6 +7,7 @@ import { useChat, useRootContext } from "../../hooks"; import "./ChatMessage.css"; interface ChatMessageProps extends IChatMessage { + timestampUpdates: number; showUser?: boolean; } @@ -27,6 +28,7 @@ export function ChatMessage({ text_censored, time, quotes, + timestampUpdates, }: ChatMessageProps) { const message = { id, @@ -46,7 +48,7 @@ export function ChatMessage({ censored, themeColor, } = useRootContext(); - const { quote, messageLookup, deleteMessage, quoteMessage } = useChat(); + const { messageLookup, deleteMessage, quoteMessage } = useChat(); const content = censored ? text_censored : text_html; const hasMention = content.includes(loggedInUsername); const mentionStyle = hasMention @@ -60,18 +62,10 @@ export function ChatMessage({ setConfirmedDelete(true); } }, [text, confirmedDelete]); - const [timestamp, setTimestamp] = useState(formatTimeAgo(time)); - - useEffect(() => { - const updatingTimestamp = setInterval( - () => setTimestamp(formatTimeAgo(time)), - TIMESTAMP_UPDATE_INTERVAL - ); - - return () => { - clearInterval(updatingTimestamp); - }; - }, []); + const timestamp = useMemo(() => formatTimeAgo(time), [ + time, + timestampUpdates, + ]); return (