1
- import { Theme , useTheme } from "@material-ui/core/styles"
1
+ import { makeStyles , Theme , useTheme } from "@material-ui/core/styles"
2
2
import { FC } from "react"
3
3
4
+ import Icon from "@material-ui/icons/Brightness1"
4
5
import dayjs from "dayjs"
5
6
import relativeTime from "dayjs/plugin/relativeTime"
7
+ import { colors } from "theme/colors"
6
8
7
9
dayjs . extend ( relativeTime )
8
10
@@ -12,28 +14,56 @@ interface WorkspaceLastUsedProps {
12
14
13
15
export const WorkspaceLastUsed : FC < WorkspaceLastUsedProps > = ( { lastUsedAt } ) => {
14
16
const theme : Theme = useTheme ( )
17
+ const styles = useStyles ( )
15
18
16
19
const t = dayjs ( lastUsedAt )
17
20
const now = dayjs ( )
18
21
19
22
let color = theme . palette . text . secondary
20
23
let message = t . fromNow ( )
24
+ let displayCircle = true
21
25
22
26
if ( t . isAfter ( now . subtract ( 1 , "hour" ) ) ) {
23
- color = theme . palette . success . main
27
+ color = colors . green [ 9 ]
24
28
// Since the agent reports on a 10m interval,
25
29
// the last_used_at can be inaccurate when recent.
26
- message = "In the last hour"
27
- } else if ( t . isAfter ( now . subtract ( 1 , "day" ) ) ) {
28
- color = theme . palette . primary . main
29
- } else if ( t . isAfter ( now . subtract ( 1 , "month" ) ) ) {
30
+ message = "Now"
31
+ } else if ( t . isAfter ( now . subtract ( 3 , "day" ) ) ) {
30
32
color = theme . palette . text . secondary
31
- } else if ( t . isAfter ( now . subtract ( 100 , "year " ) ) ) {
33
+ } else if ( t . isAfter ( now . subtract ( 1 , "month " ) ) ) {
32
34
color = theme . palette . warning . light
35
+ } else if ( t . isAfter ( now . subtract ( 100 , "year" ) ) ) {
36
+ color = colors . red [ 10 ]
33
37
} else {
34
- color = theme . palette . error . light
38
+ // color = theme.palette.error.light
35
39
message = "Never"
40
+ displayCircle = false
36
41
}
37
42
38
- return < span style = { { color : color } } > { message } </ span >
43
+ return (
44
+ < span className = { styles . root } >
45
+ < span
46
+ style = { {
47
+ color : color ,
48
+ display : displayCircle ? undefined : "none" ,
49
+ } }
50
+ >
51
+ < Icon className = { styles . icon } />
52
+ </ span >
53
+ { message }
54
+ </ span >
55
+ )
39
56
}
57
+
58
+ const useStyles = makeStyles ( ( theme ) => ( {
59
+ root : {
60
+ display : "flex" ,
61
+ alignItems : "center" ,
62
+ color : theme . palette . text . secondary ,
63
+ } ,
64
+ icon : {
65
+ marginRight : 8 ,
66
+ width : 10 ,
67
+ height : 10 ,
68
+ } ,
69
+ } ) )
0 commit comments