File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed
Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change 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
88import { dateFromNow } from '../../src/common/utils' ;
99
1010export 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} ;
You can’t perform that action at this time.
0 commit comments