-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathRouteStatistics.tsx
More file actions
27 lines (23 loc) · 1.01 KB
/
RouteStatistics.tsx
File metadata and controls
27 lines (23 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import type { VoidComponent } from 'solid-js'
import type { TimelineStatistics } from '~/api/derived'
import { formatDistance, formatRouteDuration } from '~/utils/format'
import StatisticBar from './StatisticBar'
import { currentRoute } from '~/store'
const formatEngagement = (timeline: TimelineStatistics | undefined): string | undefined => {
if (!timeline || timeline.duration === 0) return undefined
const { engagedDuration, duration } = timeline
return `${(100 * (engagedDuration / duration)).toFixed(0)}%`
}
const RouteStatistics: VoidComponent<{ class?: string; timeline: TimelineStatistics | undefined }> = (props) => {
return (
<StatisticBar
class={props.class}
statistics={[
{ label: 'Distance', value: () => formatDistance(currentRoute()?.length) },
{ label: 'Duration', value: () => (currentRoute() ? formatRouteDuration(currentRoute()) : undefined) },
{ label: 'Engaged', value: () => formatEngagement(props.timeline) },
]}
/>
)
}
export default RouteStatistics