Skip to content

Commit 3f73243

Browse files
authored
feat: improve formatting of last used (#3824)
1 parent 2d34765 commit 3f73243

File tree

1 file changed

+39
-9
lines changed

1 file changed

+39
-9
lines changed
Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { Theme, useTheme } from "@material-ui/core/styles"
1+
import { makeStyles, Theme, useTheme } from "@material-ui/core/styles"
22
import { FC } from "react"
33

4+
import Icon from "@material-ui/icons/Brightness1"
45
import dayjs from "dayjs"
56
import relativeTime from "dayjs/plugin/relativeTime"
7+
import { colors } from "theme/colors"
68

79
dayjs.extend(relativeTime)
810

@@ -12,28 +14,56 @@ interface WorkspaceLastUsedProps {
1214

1315
export const WorkspaceLastUsed: FC<WorkspaceLastUsedProps> = ({ lastUsedAt }) => {
1416
const theme: Theme = useTheme()
17+
const styles = useStyles()
1518

1619
const t = dayjs(lastUsedAt)
1720
const now = dayjs()
1821

1922
let color = theme.palette.text.secondary
2023
let message = t.fromNow()
24+
let displayCircle = true
2125

2226
if (t.isAfter(now.subtract(1, "hour"))) {
23-
color = theme.palette.success.main
27+
color = colors.green[9]
2428
// Since the agent reports on a 10m interval,
2529
// 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"))) {
3032
color = theme.palette.text.secondary
31-
} else if (t.isAfter(now.subtract(100, "year"))) {
33+
} else if (t.isAfter(now.subtract(1, "month"))) {
3234
color = theme.palette.warning.light
35+
} else if (t.isAfter(now.subtract(100, "year"))) {
36+
color = colors.red[10]
3337
} else {
34-
color = theme.palette.error.light
38+
// color = theme.palette.error.light
3539
message = "Never"
40+
displayCircle = false
3641
}
3742

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+
)
3956
}
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

Comments
 (0)