-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add badge indicating kit active status
- Loading branch information
Showing
5 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
.active { | ||
--color1: oklch(76% 0.12 151.19); | ||
--color2: oklch(72% 0.12 151.19); | ||
} | ||
|
||
.recentlyActive { | ||
--color1: oklch(76% 0.12 70.5); | ||
--color2: oklch(72% 0.12 70.5); | ||
} | ||
|
||
.inactive, | ||
.neverSeen { | ||
--color1: oklch(76% 0.0 70.5); | ||
--color2: oklch(72% 0.0 70.5); | ||
} | ||
|
||
.badge { | ||
border-radius: 100%; | ||
width: 1rem; | ||
height: 1rem; | ||
background: linear-gradient(225deg, var(--color1), var(--color2)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { DateTime, Duration } from "luxon"; | ||
import { useMemo } from "react"; | ||
|
||
import { schemas } from "~/api"; | ||
import { useTime } from "~/hooks"; | ||
|
||
import style from "./KitActiveBadge.module.css"; | ||
import clsx from "clsx"; | ||
|
||
export function KitActiveBadge({ kit }: { kit: schemas["Kit"] }) { | ||
const now = useTime(Duration.fromMillis(10000)); | ||
|
||
const [activeClass, title] = useMemo(() => { | ||
if (kit.lastSeen === undefined || kit.lastSeen === null) { | ||
return ["neverSeen", "Never seen"]; | ||
} else { | ||
const lastSeen = DateTime.fromISO(kit.lastSeen); | ||
const ago = now.diff(lastSeen); | ||
|
||
let activeClass; | ||
if (ago.as("minutes") < 10) { | ||
activeClass = "active"; | ||
} else if (ago.as("hours") < 4) { | ||
activeClass = "recentlyActive"; | ||
} else { | ||
activeClass = "inactive"; | ||
} | ||
|
||
return [ | ||
activeClass, | ||
`Last seen ${lastSeen.toLocaleString(DateTime.DATETIME_SHORT)}`, | ||
]; | ||
} | ||
}, [now, kit]); | ||
|
||
return ( | ||
<> | ||
<span | ||
role="status" | ||
className={clsx(style.badge, style[activeClass])} | ||
title={title} | ||
></span> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters