Skip to content

Commit 14856fd

Browse files
Copilotalexr00
andcommitted
Implement periodic timestamp updates in timeline
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent e9e139d commit 14856fd

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

.eslintcache.browser

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

webviews/components/timestamp.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,34 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import * as React from 'react';
6+
import React, { useEffect, useState } from 'react';
77

88
import { dateFromNow } from '../../src/common/utils';
99

1010
export const Timestamp = ({ date, href }: { date: Date | string; href?: string }) => {
11+
const [timeString, setTimeString] = useState(dateFromNow(date));
1112
const title = typeof date === 'string' ? new Date(date).toLocaleString() : date.toLocaleString();
13+
14+
useEffect(() => {
15+
// Update the time string immediately
16+
setTimeString(dateFromNow(date));
17+
18+
// Set up an interval to update the time string every minute
19+
const intervalId = setInterval(() => {
20+
setTimeString(dateFromNow(date));
21+
}, 60000); // Update every 60 seconds
22+
23+
// Clean up the interval on component unmount
24+
return () => clearInterval(intervalId);
25+
}, [date]);
26+
1227
return href ? (
1328
<a href={href} className="timestamp" title={title}>
14-
{dateFromNow(date)}
29+
{timeString}
1530
</a>
1631
) : (
1732
<div className="timestamp" title={title}>
18-
{dateFromNow(date)}
33+
{timeString}
1934
</div>
2035
);
2136
};

0 commit comments

Comments
 (0)