Skip to content

Commit

Permalink
Only calls setTimestamps if a new timestamp is added
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonWeill committed May 17, 2023
1 parent 23ded67 commit 3f0d16e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/jupyter-ai/src/components/chat-messages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ export function ChatMessages(props: ChatMessagesProps) {
useEffect(() => {
function updateTimestamps() {
const newTimestamps: Record<string, string> = {};
let timestampAdded: boolean = false;

for (const message of props.messages) {
if (!(message.id in newTimestamps)) {
// Use the browser's default locale
Expand All @@ -119,9 +121,13 @@ export function ChatMessages(props: ChatMessagesProps) {
hour: 'numeric', // Avoid leading zero for hours; we don't want "03:15 PM"
minute: '2-digit'
});

timestampAdded = true;
}
}
setTimestamps(newTimestamps);
if (timestampAdded) {
setTimestamps(newTimestamps);
}
}

updateTimestamps();
Expand Down

0 comments on commit 3f0d16e

Please sign in to comment.