@@ -7,18 +7,29 @@ import moment from "moment";
7
7
8
8
import { useSpace } from "hooks/useSpace" ;
9
9
10
- const Display = styled . div `
10
+ const Display = styled . div < { isUrgent : boolean } > `
11
11
position: absolute;
12
12
display: flex;
13
- align-items: center;
13
+ flex-direction: column;
14
+ align-items: end;
14
15
background-color: #383838;
15
16
padding: 0.5em;
16
17
top: 12px;
17
18
right: 12px;
19
+ font-size: 1.5em;
18
20
font-variant-numeric: tabular-nums;
19
21
color: white;
20
22
user-select: none;
21
23
border-radius: 3px;
24
+ z-index: 200;
25
+
26
+ ${ ( props ) =>
27
+ props . isUrgent &&
28
+ `
29
+ #countdown {
30
+ color: red;
31
+ }
32
+ ` }
22
33
` ;
23
34
24
35
const getClock = ( diff : number ) => {
@@ -33,10 +44,12 @@ const getClock = (diff: number) => {
33
44
34
45
const Timer = ( ) : JSX . Element => {
35
46
const { spaceEndsAt, leaveSpace } = useSpace ( ) ;
47
+ const diff = moment ( spaceEndsAt ) . diff ( moment ( ) ) ;
36
48
const [ timeDisplay , setTimeDisplay ] = useState < string > (
37
- spaceEndsAt ? getClock ( moment ( spaceEndsAt ) . diff ( moment ( ) ) ) : "00:00"
49
+ spaceEndsAt ? getClock ( diff ) : "00:00"
38
50
) ;
39
51
const router = useRouter ( ) ;
52
+ const twoMinutesleft = 120 >= Math . floor ( diff / 1000 ) ;
40
53
41
54
useEffect ( ( ) => {
42
55
const timer = setInterval ( ( ) => {
@@ -54,15 +67,13 @@ const Timer = (): JSX.Element => {
54
67
} , [ router , leaveSpace , spaceEndsAt ] ) ;
55
68
56
69
return (
57
- < Tooltip label = "This temporary space will close after the timer expires." >
58
- < Display >
59
- < Box marginRight = "6px" >
60
- < MdTimer size = "20px" />
61
- </ Box > { " " }
62
- { timeDisplay }
70
+ < Tooltip label = "This demo space will close after the timer expires." >
71
+ < Display isUrgent = { twoMinutesleft } >
72
+ < span > Time Left</ span >
73
+ < span id = "countdown" > { timeDisplay } </ span >
63
74
</ Display >
64
75
</ Tooltip >
65
76
) ;
66
77
} ;
67
78
68
- export default Timer ;
79
+ export default Timer ;
0 commit comments