Skip to content

Commit 7dd716e

Browse files
committed
update
1 parent 1503217 commit 7dd716e

File tree

2 files changed

+51
-36
lines changed

2 files changed

+51
-36
lines changed

src/pages/dashboard/components/RouteList.tsx

+31-36
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
Index,
77
onCleanup,
88
onMount,
9+
Show,
910
Suspense,
1011
type VoidComponent,
1112
} from 'solid-js'
@@ -15,19 +16,15 @@ import { getTimelineStatistics, TimelineStatistics } from '~/api/derived'
1516
import Card, { CardContent, CardHeader } from '~/components/material/Card'
1617
import Icon from '~/components/material/Icon'
1718
import type { RouteSegments } from '~/types'
18-
import { formatRouteDistance, formatRouteDuration } from '~/utils/date'
19+
import { formatDateRange, formatRouteDistance, formatRouteDuration, formatTimeRange } from '~/utils/date'
1920
import { useDimensions } from '~/utils/window'
2021

2122

22-
const formatEngagement = (timeline?: TimelineStatistics): string => {
23-
if (!timeline) return ''
23+
const getEngagement = (timeline?: TimelineStatistics): string | null => {
24+
if (!timeline) return null
2425
const { engagedDuration, duration } = timeline
25-
return `Engaged Time: ${(100 * (engagedDuration / duration)).toFixed(0)}%`
26-
}
27-
28-
29-
const formatUserFlags = (timeline?: TimelineStatistics): string => {
30-
return timeline?.userFlags !== undefined ? `${timeline.userFlags} user flags` : ''
26+
if (!duration) return null
27+
return `${(100 * (engagedDuration / duration)).toFixed(0)}%`
3128
}
3229

3330

@@ -36,17 +33,8 @@ interface RouteCardProps {
3633
}
3734

3835
const RouteCard: VoidComponent<RouteCardProps> = (props) => {
39-
// TODO: move to date utils
40-
const dateRange = () => new Intl.DateTimeFormat('en', {
41-
weekday: 'long',
42-
day: 'numeric',
43-
month: 'long',
44-
year: 'numeric',
45-
}).formatRange(props.route.start_time_utc_millis, props.route.end_time_utc_millis)
46-
const timeRange = () => new Intl.DateTimeFormat('en', {
47-
hour: 'numeric',
48-
minute: 'numeric',
49-
}).formatRange(props.route.start_time_utc_millis, props.route.end_time_utc_millis)
36+
const dateRange = () => formatDateRange(props.route.start_time_utc_millis, props.route.end_time_utc_millis)
37+
const timeRange = () => formatTimeRange(props.route.start_time_utc_millis, props.route.end_time_utc_millis)
5038
const [timeline] = createResource(() => props.route, getTimelineStatistics)
5139

5240
return (
@@ -55,29 +43,36 @@ const RouteCard: VoidComponent<RouteCardProps> = (props) => {
5543
href={`/${props.route.dongle_id}/${props.route.fullname.slice(17)}`}
5644
activeClass="md:before:bg-primary"
5745
>
58-
<CardHeader headline={dateRange()} subhead={timeRange()} />
46+
<CardHeader
47+
headline={dateRange()}
48+
subhead={timeRange()}
49+
trailing={<div class="flex flex-row gap-2">
50+
<Icon size="24">route</Icon>
51+
{formatRouteDistance(props.route)}
52+
</div>}
53+
/>
5954

6055
<CardContent>
61-
<div class="grid size-full grid-cols-2 gap-4">
56+
<div class="grid gap-2 grid-cols-3 whitespace-nowrap">
6257
<div class="flex items-center gap-2">
6358
<Icon size="20">schedule</Icon>
6459
{formatRouteDuration(props.route)}
6560
</div>
66-
<div class="flex items-center gap-2">
67-
<Icon size="20">route</Icon>
68-
{formatRouteDistance(props.route)}
69-
</div>
70-
<Suspense fallback={<div class="skeleton-loader h-6" />}>
71-
<div class="hidden items-center gap-2 xs:flex">
72-
<Icon size="20">speed</Icon>
73-
{formatEngagement(timeline())}
74-
</div>
61+
<Suspense fallback={<div class="flex h-6"><div class="skeleton-loader size-full" /></div>}>
62+
<Show when={getEngagement(timeline())}>{(engagement) => (
63+
<div class="hidden items-center gap-2 xs:flex">
64+
<Icon size="20">speed</Icon>
65+
<span>Engaged: {engagement()}</span>
66+
</div>
67+
)}</Show>
7568
</Suspense>
76-
<Suspense fallback={<div class="skeleton-loader h-6" />}>
77-
<div class="flex items-center gap-2">
78-
<Icon size="20">flag</Icon>
79-
{formatUserFlags(timeline())}
80-
</div>
69+
<Suspense fallback={<div class="flex h-6"><div class="skeleton-loader size-full" /></div>}>
70+
<Show when={timeline()}>{(timeline) => (
71+
<div class="flex items-center gap-2 justify-self-end ps-2">
72+
<Icon size="20">flag</Icon>
73+
<span>{timeline()?.userFlags} <span class="hidden xs:inline">user</span> flags</span>
74+
</div>
75+
)}</Show>
8176
</Suspense>
8277
</div>
8378
</CardContent>

src/utils/date.ts

+20
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,23 @@ export const formatDate = (input: dayjs.ConfigType) => {
6262
const yearStr = date.year() === dayjs().year() ? '' : ', YYYY'
6363
return date.format('MMMM Do' + yearStr)
6464
}
65+
66+
const LONG_DATE_FORMAT = new Intl.DateTimeFormat('en', {
67+
weekday: 'long',
68+
day: 'numeric',
69+
month: 'long',
70+
year: 'numeric',
71+
})
72+
73+
const TIME_FORMAT = new Intl.DateTimeFormat('en', {
74+
hour: 'numeric',
75+
minute: 'numeric',
76+
})
77+
78+
export const formatDateRange = (start: number, end: number): string => {
79+
return LONG_DATE_FORMAT.formatRange(start, end)
80+
}
81+
82+
export const formatTimeRange = (start: number, end: number): string => {
83+
return TIME_FORMAT.formatRange(start, end)
84+
}

0 commit comments

Comments
 (0)