diff --git a/assets/src/components/detourListPage.tsx b/assets/src/components/detourListPage.tsx
index 0193a2513..fa605fecc 100644
--- a/assets/src/components/detourListPage.tsx
+++ b/assets/src/components/detourListPage.tsx
@@ -1,7 +1,11 @@
import React, { useCallback, useState } from "react"
-import { DetoursTable, DetourStatus } from "./detoursTable"
+import {
+ DetoursTable,
+ DetourStatus,
+ timestampLabelFromStatus,
+} from "./detoursTable"
import userInTestGroup, { TestGroups } from "../userInTestGroup"
-import { Button } from "react-bootstrap"
+import { Button, Table } from "react-bootstrap"
import {
GlobeAmericas,
LockFill,
@@ -16,6 +20,9 @@ import { isErr, isOk } from "../util/result"
import { isValidSnapshot } from "../util/isValidSnapshot"
import { createDetourMachine } from "../models/createDetourMachine"
import { joinClasses } from "../helpers/dom"
+import { RoutePill } from "./routePill"
+import { timeAgoLabelForDates } from "../util/dateTime"
+import { useCurrentTime } from "../hooks/useCurrentTime"
export const DetourListPage = () => {
const [showDetourModal, setShowDetourModal] = useState(false)
@@ -55,6 +62,8 @@ export const DetourListPage = () => {
setShowDetourModal(false)
}
+ const epochNow = useCurrentTime()
+
return (
{userInTestGroup(TestGroups.DetoursPilot) && (
@@ -75,12 +84,53 @@ export const DetourListPage = () => {
visibility="All Skate users"
classNames={["d-flex"]}
/>
-
+
+
+
+ Route and direction |
+
+ Starting Intersection
+ |
+
+ {timestampLabelFromStatus(DetourStatus.Active)}
+ |
+
+
+
+ {detours.active
+ ? detours.active.map((detour, index) => (
+ onOpenDetour(detour.details.id)}
+ >
+
+
+
+
+
+ {detour.details.name}
+
+
+ {detour.details.direction}
+
+
+
+ |
+
+ {detour.details.intersection}
+ |
+
+ {timeAgoLabelForDates(detour.activatedAt, epochNow)}
+ |
+
+ ))
+ : null}
+
+
{userInTestGroup(TestGroups.DetoursPilot) && (
<>
{
+export const useCurrentTime = (): Date => {
const [currentTime, setCurrentTime] = useState(now())
useInterval(() => setCurrentTime(now()), 1000)
return currentTime
diff --git a/assets/src/models/detoursList.ts b/assets/src/models/detoursList.ts
index 8df56eb96..1d004ea7a 100644
--- a/assets/src/models/detoursList.ts
+++ b/assets/src/models/detoursList.ts
@@ -1,4 +1,13 @@
-import { array, Infer, nullable, number, string, type } from "superstruct"
+import {
+ array,
+ coerce,
+ date,
+ Infer,
+ nullable,
+ number,
+ string,
+ type,
+} from "superstruct"
export type DetourId = number
export interface SimpleDetour {
@@ -10,6 +19,11 @@ export interface SimpleDetour {
updatedAt: number
}
+export interface ActivatedDetour {
+ activatedAt: Date
+ details: SimpleDetour
+}
+
export const detourId = number()
export const SimpleDetourData = type({
id: detourId,
@@ -20,6 +34,11 @@ export const SimpleDetourData = type({
updated_at: number(),
})
+export const ActivatedDetourData = type({
+ activated_at: coerce(date(), string(), (dateStr) => new Date(dateStr)),
+ details: SimpleDetourData,
+})
+
export type SimpleDetourData = Infer
export const simpleDetourFromData = (
@@ -34,13 +53,13 @@ export const simpleDetourFromData = (
})
export interface GroupedSimpleDetours {
- active?: SimpleDetour[]
+ active?: ActivatedDetour[]
draft?: SimpleDetour[]
past?: SimpleDetour[]
}
export const GroupedDetoursData = type({
- active: nullable(array(SimpleDetourData)),
+ active: nullable(array(ActivatedDetourData)),
draft: nullable(array(SimpleDetourData)),
past: nullable(array(SimpleDetourData)),
})
@@ -50,7 +69,10 @@ export type GroupedDetoursData = Infer
export const groupedDetoursFromData = (
groupedDetours: GroupedDetoursData
): GroupedSimpleDetours => ({
- active: groupedDetours.active?.map((detour) => simpleDetourFromData(detour)),
+ active: groupedDetours.active?.map((detour) => ({
+ details: simpleDetourFromData(detour.details),
+ activatedAt: detour.activated_at,
+ })),
draft: groupedDetours.draft?.map((detour) => simpleDetourFromData(detour)),
past: groupedDetours.past?.map((detour) => simpleDetourFromData(detour)),
})
diff --git a/assets/src/util/dateTime.ts b/assets/src/util/dateTime.ts
index 305331ede..8d5582fc8 100644
--- a/assets/src/util/dateTime.ts
+++ b/assets/src/util/dateTime.ts
@@ -94,13 +94,27 @@ export const secondsAgoLabel = (
epochTime: number
): string => `${epochNowInSeconds - epochTime}s ago`
+const second = 1000
+const minute = second * 60
+const hour = minute * 60
+
export const timeAgoLabel = (
epochNowInSeconds: number,
epochTime: number
): string => {
const duration = epochNowInSeconds - epochTime
- const diffHours = Math.floor(duration / 3_600)
- const diffMinutes = Math.floor((duration % 3_600) / 60)
- return diffHours >= 1 ? `${diffHours} hours ago` : `${diffMinutes} min ago`
+ if (duration > 1 * hour) {
+ return `${Math.floor(duration / hour)} hours ago`
+ }
+
+ if (duration > 1 * minute) {
+ return `${Math.floor(duration / minute)} min ago`
+ }
+
+ return "Just now"
+}
+
+export const timeAgoLabelForDates = (start: Date, end: Date) => {
+ return timeAgoLabel(end.valueOf() / second, start.valueOf() / second)
}
diff --git a/assets/tests/components/detours/__snapshots__/detourListPage.test.tsx.snap b/assets/tests/components/detours/__snapshots__/detourListPage.test.tsx.snap
index 1610141e0..72509ae3f 100644
--- a/assets/tests/components/detours/__snapshots__/detourListPage.test.tsx.snap
+++ b/assets/tests/components/detours/__snapshots__/detourListPage.test.tsx.snap
@@ -121,7 +121,7 @@ exports[`DetourListPage renders detour list page for dispatchers 1`] = `
- 26 hours ago
+ 1 min ago
|
@@ -160,7 +160,7 @@ exports[`DetourListPage renders detour list page for dispatchers 1`] = `
- 29 hours ago
+ 1 min ago
|
@@ -349,7 +349,7 @@ exports[`DetourListPage renders detour list page for dispatchers 1`] = `
- 26 hours ago
+ 1 min ago
|
@@ -388,7 +388,7 @@ exports[`DetourListPage renders detour list page for dispatchers 1`] = `
- 26 hours ago
+ 1 min ago
|
@@ -492,7 +492,7 @@ exports[`DetourListPage renders limited detour list page for non-dispatchers 1`]
- 26 hours ago
+ 1 min ago
|
@@ -531,7 +531,7 @@ exports[`DetourListPage renders limited detour list page for non-dispatchers 1`]
- 29 hours ago
+ 1 min ago
|
diff --git a/assets/tests/components/detours/__snapshots__/detoursListPage.openDetour.test.tsx.snap b/assets/tests/components/detours/__snapshots__/detoursListPage.openDetour.test.tsx.snap
index 75670605e..381d5cef3 100644
--- a/assets/tests/components/detours/__snapshots__/detoursListPage.openDetour.test.tsx.snap
+++ b/assets/tests/components/detours/__snapshots__/detoursListPage.openDetour.test.tsx.snap
@@ -124,7 +124,7 @@ exports[`Detours Page: Open a Detour renders detour details in an open drawer on
- 26 hours ago
+ Just now
|
@@ -163,7 +163,7 @@ exports[`Detours Page: Open a Detour renders detour details in an open drawer on
- 26 hours ago
+ Just now
|
@@ -352,7 +352,7 @@ exports[`Detours Page: Open a Detour renders detour details in an open drawer on
- 26 hours ago
+ 1 min ago
|
@@ -971,7 +971,7 @@ exports[`Detours Page: Open a Detour renders detour details modal to match mocke
- 26 hours ago
+ Just now
|
@@ -1010,7 +1010,7 @@ exports[`Detours Page: Open a Detour renders detour details modal to match mocke
- 26 hours ago
+ Just now
|
@@ -1199,7 +1199,7 @@ exports[`Detours Page: Open a Detour renders detour details modal to match mocke
- 26 hours ago
+ 1 min ago
|
@@ -1228,7 +1228,7 @@ exports[`Detours Page: Open a Detour renders detour details modal to match mocke
>
Last edited
- 26 hours ago
+ 1 min ago