File tree Expand file tree Collapse file tree 1 file changed +15
-6
lines changed
Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Original file line number Diff line number Diff line change 66 formatUserTime ,
77 toUserTime ,
88} from './time'
9+ import { formatDistance } from 'date-fns'
10+
11+ const diff = ( startTime : Date ) => formatDistance ( startTime , new Date ( ) )
912
1013const startsInMinutes = ( startTime : Date ) => {
1114 return Math . floor ( ( startTime . getTime ( ) - Date . now ( ) ) / 1000 / 60 )
@@ -18,23 +21,29 @@ const Countdown = ({
1821 startTime : Date
1922 warnTime ?: number
2023} ) => {
21- const [ timeToStart , setTimeToStart ] = React . useState (
22- startsInMinutes ( startTime ) ,
23- )
24+ const [ timeToStart , setTimeToStart ] = React . useState ( {
25+ text : diff ( startTime ) ,
26+ minutes : startsInMinutes ( startTime ) ,
27+ } )
2428 React . useEffect ( ( ) => {
2529 const interval = setInterval ( ( ) => {
26- setTimeToStart ( startsInMinutes ( startTime ) )
30+ setTimeToStart ( {
31+ text : diff ( startTime ) ,
32+ minutes : startsInMinutes ( startTime ) ,
33+ } )
2734 } , 1000 * 60 )
2835
2936 return ( ) => clearInterval ( interval )
3037 } , [ startTime ] )
3138 return (
3239 < td
3340 className = {
34- timeToStart > 0 && timeToStart <= ( warnTime || 5 ) ? 'time hot' : 'time'
41+ timeToStart . minutes > 0 && timeToStart . minutes <= ( warnTime || 5 )
42+ ? 'time hot'
43+ : 'time'
3544 }
3645 >
37- { timeToStart > 0 ? ` ${ timeToStart } m` : '-' }
46+ { timeToStart . minutes > 0 ? timeToStart . text : '-' }
3847 </ td >
3948 )
4049}
You can’t perform that action at this time.
0 commit comments