Skip to content

Commit 0d6bfef

Browse files
authored
Merge pull request #15 from SliceOSM/jlow/last-updated-color
Make last updated chip yellow if time > 15 min ago
2 parents c92f52e + 4af2084 commit 0d6bfef

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/LastUpdated.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useEffect, useState } from "react";
2-
import { formatDistanceToNow, parseISO, formatISO } from "date-fns";
2+
import { formatDistanceToNow, differenceInSeconds, parseISO, formatISO } from "date-fns";
33
import { API_ENDPOINT } from "./Common";
44

55
const LastUpdated = () => {
@@ -17,9 +17,12 @@ const LastUpdated = () => {
1717
// Loading state
1818
return <span className="chip">...</span>;
1919
}
20+
21+
const chipColor = differenceInSeconds(new Date(), updatedTimestamp) > (15 * 60)
22+
? "chip-yellow" : "chip-green";
2023

2124
return (
22-
<span className="chip">
25+
<span className={`chip ${chipColor}`}>
2326
{"Data updated "}
2427
<time dateTime={formatISO(updatedTimestamp)} title={updatedTimestamp.toString()}>
2528
{formatDistanceToNow(updatedTimestamp)} ago

src/main.css

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,19 +88,37 @@ main > footer {
8888
font-size: 0.9em;
8989
display: inline-block;
9090
color: white;
91-
background-color: hsl(150, 55%, 20%);
91+
background-color: hsl(0, 0%, 25%);
9292
border-radius: 9999px;
9393
padding-top: 0.2em;
9494
padding-bottom: 0.05em;
9595
padding-inline: 0.6em;
9696
}
9797

98-
.chip::before {
98+
.chip-green {
99+
background-color: hsl(150, 55%, 20%);
100+
}
101+
102+
.chip-yellow {
103+
background-color: hsl(45, 75%, 27%);
104+
}
105+
106+
.chip-green::before {
99107
content: '●';
100-
color: #31c48d;
108+
color: hsl(158, 60%, 48%);
101109
margin-right: 0.25em;
102110
}
103111

112+
.chip-yellow::before {
113+
content: '●';
114+
color: hsl(48, 100%, 50%);
115+
margin-right: 0.25em;
116+
}
117+
118+
.chip time[title] {
119+
text-decoration: underline dotted rgba(255, 255, 255, 0.75);
120+
}
121+
104122
.neon-red {
105123
color: rgba(255, 255, 255, 0.7);
106124
text-shadow:

0 commit comments

Comments
 (0)