Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dashboard UI overhaul #42

Draft
wants to merge 31 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a0676e6
Built wireframe UI
vishalkrishnads Jun 24, 2024
9ea473d
new routeactivity structure
vishalkrishnads Jun 25, 2024
97c4276
removed empty console.logs
vishalkrishnads Jun 26, 2024
d3cd5d9
add device button
vishalkrishnads Jun 26, 2024
e2f3490
implemented filters
vishalkrishnads Jun 26, 2024
e34594d
improved search
vishalkrishnads Jun 26, 2024
1c2b30f
minor fixes
vishalkrishnads Jun 26, 2024
d7b160f
added speed to video
vishalkrishnads Jun 26, 2024
6681dba
added dynamic bearing to map
vishalkrishnads Jun 26, 2024
9bf8744
separated speed units
vishalkrishnads Jun 26, 2024
3ae3dae
fixed navigation issue
vishalkrishnads Jun 26, 2024
3912772
Fixed no device name
vishalkrishnads Jun 26, 2024
f500226
minor type fix
vishalkrishnads Jun 26, 2024
aae60de
loosened rejection
vishalkrishnads Jun 26, 2024
f7d383d
improved empty placeholder
vishalkrishnads Jun 26, 2024
2da71cf
improved place naming
vishalkrishnads Jun 26, 2024
fbef98c
added device stats
vishalkrishnads Jun 26, 2024
e01fcae
fixed load more not visible
vishalkrishnads Jun 26, 2024
3af8879
logout button
vishalkrishnads Jun 26, 2024
49c7f8a
smoothened map bearing
vishalkrishnads Jun 26, 2024
4ecea7f
checked preserve toggle
vishalkrishnads Jun 26, 2024
e932cfd
bun lock
vishalkrishnads Jun 26, 2024
5517d2f
removed frozen lockfile
vishalkrishnads Jun 26, 2024
2132b72
improved loading flow
vishalkrishnads Jun 27, 2024
7eb02de
implemented david's changes
vishalkrishnads Jun 27, 2024
636113c
fixed search bug
vishalkrishnads Jun 27, 2024
69f197d
changed mobile view
vishalkrishnads Jun 27, 2024
a513518
converted speed to mph
vishalkrishnads Jul 1, 2024
aa7eaf3
re-trigger workflow
vishalkrishnads Jul 4, 2024
c7d211e
Merge remote-tracking branch 'origin' into ui
vishalkrishnads Jul 8, 2024
0258663
fixed frozen lockfile
vishalkrishnads Jul 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
Binary file not shown.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@
},
"dependencies": {
"@mapbox/polyline": "^1.2.1",
"@solid-primitives/keyboard": "^1.2.8",
"@solidjs/router": "^0.13.5",
"clsx": "^1.2.1",
"dayjs": "^1.11.11",
"hls.js": "^1.5.11",
"solid-js": "^1.8.17"
"mapbox-gl": "^3.4.0",
"solid-js": "^1.8.17",
"solid-map-gl": "^1.11.3"
},
"engines": {
"node": ">=20.11.0"
Expand Down
1 change: 1 addition & 0 deletions public/images/logo-connect-placeholder.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const App: VoidComponent = () => {
<Route path="/logout" component={Logout} />
<Route path="/auth" component={Auth} />

<Route path="/*dongleId" component={Dashboard} />
<Route path="*" component={Dashboard} />
</Router>
)
}
Expand Down
47 changes: 45 additions & 2 deletions src/api/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { fetcher } from '.'
import { BASE_URL } from './config'
import type { Device, Route, RouteShareSignature } from '~/types'
import { TimelineStatistics } from './derived'
import { getPlaceFromCoords } from '~/map'
import { getTimelineStatistics } from './derived'
import { formatRouteDistance, getRouteDuration } from '~/utils/date'

export class RouteName {
// dongle ID date str
Expand Down Expand Up @@ -33,8 +37,47 @@ export class RouteName {
}
}

export const getRoute = (routeName: Route['fullname']): Promise<Route> =>
fetcher<Route>(`/v1/route/${routeName}/`)
const formatEngagement = (timeline?: TimelineStatistics): number => {
if (!timeline) return 0
const { engagedDuration, duration } = timeline
return parseInt((100 * (engagedDuration / duration)).toFixed(0))
}

const formatUserFlags = (timeline?: TimelineStatistics): number => {
return timeline?.userFlags ?? 0
}

export const getDerivedData = async(route: Route): Promise<Route> => {
const [startPlace, endPlace, timeline] = await Promise.all([
getPlaceFromCoords(route.start_lng, route.start_lat),
getPlaceFromCoords(route.end_lng, route.end_lat),
getTimelineStatistics(route),
])

route.ui_derived = {
distance: formatRouteDistance(route),
duration: getRouteDuration(route),
flags: formatUserFlags(timeline),
engagement: formatEngagement(timeline),
address: {
start: startPlace,
end: endPlace,
},
}

return route
}

export const getRoute = (routeName: Route['fullname']): Promise<Route> => {
return new Promise((resolve, reject) => {
fetcher<Route>(`/v1/route/${routeName}/`)
.then(route => {
getDerivedData(route)
.then(res => resolve(res))
.catch(() => resolve(route))
}).catch(err => reject(err))
})
}

export const getRouteShareSignature = (routeName: string): Promise<RouteShareSignature> =>
fetcher(`/v1/route/${routeName}/share_signature`)
Expand Down
62 changes: 62 additions & 0 deletions src/api/routelist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import type { RouteSegments } from '~/types'
import { fetcher } from '.'
import { formatRouteDistance, getRouteDuration } from '~/utils/date'
import { TimelineStatistics, getTimelineStatistics } from '~/api/derived'
import { getPlaceFromCoords } from '~/map'

const formatEngagement = (timeline?: TimelineStatistics): number => {
if (!timeline) return 0
const { engagedDuration, duration } = timeline
return parseInt((100 * (engagedDuration / duration)).toFixed(0))
}

const formatUserFlags = (timeline?: TimelineStatistics): number => {
return timeline?.userFlags ?? 0
}

const endpoint = (dongleId: string | undefined, page_size: number) => `/v1/devices/${dongleId}/routes_segments?limit=${page_size}`
export const getKey = (
dongleId:string | undefined, page_size: number, previousPageData?: RouteSegments[],
): string | undefined => {
if (!previousPageData && dongleId) return endpoint(dongleId, page_size)
if(previousPageData) { // just to satisfy typescript
if (previousPageData.length === 0) return undefined
const lastSegmentEndTime = previousPageData.at(-1)!.segment_start_times.at(-1)!
return `${endpoint(dongleId, page_size)}&end=${lastSegmentEndTime - 1}`
}
}

export const getRouteCardsData = async (url: string | undefined): Promise<RouteSegments[]> => {
if (!url) return []

try {
const res = await fetcher<RouteSegments[]>(url)

// TODO: use getDerviedData() /api/routes here to reduce code
const updatedRes = await Promise.all(res.map(async (each) => {
const [startPlace, endPlace, timeline] = await Promise.all([
getPlaceFromCoords(each.start_lng, each.start_lat),
getPlaceFromCoords(each.end_lng, each.end_lat),
getTimelineStatistics(each),
])

each.ui_derived = {
distance: formatRouteDistance(each),
duration: getRouteDuration(each),
flags: formatUserFlags(timeline),
engagement: formatEngagement(timeline),
address: {
start: startPlace,
end: endPlace,
},
}

return each
}))

return updatedRes
} catch (err) {
console.error(err)
return []
}
}
106 changes: 106 additions & 0 deletions src/components/Dates.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { VoidComponent, createEffect, createSignal, onMount, useContext } from 'solid-js'
import Button from './material/Button'
import Avatar from './material/Avatar'
import Icon from './material/Icon'
import Modal from './Modal'
import { DashboardContext, generateContextType } from '~/pages/dashboard/Dashboard'

type Props = {
start: Date | null,
end: Date | null,
visible: boolean,
onSelect: (start: Date, end: Date) => void
}

type InputProps = {
value: Date
onSelect: (value: Date) => void
}
const Input: VoidComponent<InputProps> = (props) => {
return <input
type="date"
class="m-1 w-4/5 bg-transparent md:w-3/5"
value={props.value.toISOString().split('T')[0]}
onChange={event => {
const value = event.target.value
props.onSelect(value ? new Date(value) : props.value)
}}
/>
}

const DatePicker: VoidComponent<Props> = (props) => {

const [visible, setVisible] = createSignal(false)
const [start, setStart] = createSignal(new Date())
const [end, setEnd] = createSignal(new Date())

createEffect(() => setVisible(props.visible))
onMount(() => {
if(props.start) setStart(props.start)
if(props.end) setEnd(props.end)
})

return <Modal visible={visible()}>
<div class="flex h-1/5 w-4/5 flex-col rounded-md bg-secondary-container opacity-100 md:w-2/5 xl:w-1/5">
<div class="flex basis-2/6 items-center justify-center">
<h2>select a date range</h2>
</div>
<div class="flex basis-3/6 items-center justify-center">
<div class="flex basis-1/6 flex-col items-end justify-center md:basis-2/6">
<p>From</p>
<p>To</p>
</div>
<div class="flex basis-4/6 flex-col p-2">
<Input value={start()} onSelect={value => setStart(value)} />
<Input value={end()} onSelect={value => setEnd(value)} />
</div>
</div>
<div class="flex basis-2/6 items-center justify-center">
<Button onClick={() => props.onSelect(start(), end())} >
<p>Set dates</p>
</Button>
</div>
</div>
</Modal>
}

type DisplayProps = {
value: Date,
isEnd?: boolean,
onClick: () => void
}

const DateDisplay: VoidComponent<DisplayProps> = (props) => {
const { isDesktop } = useContext(DashboardContext) ?? generateContextType()
return <div onClick={() => props.onClick()} class={`flex basis-1/2 flex-col ${props.isEnd && 'items-end'} justify-center`}>
<p class="text-sm text-on-secondary-container">{props.isEnd ? 'To' : 'From'}</p>
<h2 class="text-lg">{props.value.toLocaleDateString('en-US', { year: 'numeric', month: isDesktop() ? 'long' : 'numeric', day: 'numeric' })}</h2>
</div>
}

const Dates: VoidComponent = () => {

const [selector, openSelector] = createSignal(false)
const [dates, setDates] = createSignal({start: new Date(), end: new Date()})

return <div class="flex size-11/12 rounded-md">
<DatePicker
visible={selector()}
start={new Date()}
end={new Date()}
onSelect={(start, end) => {
setDates({ start, end })
openSelector(false)
}}
/>
<DateDisplay onClick={() => openSelector(true)} value={dates().start} />
<div class="flex basis-1/5 items-center justify-center">
<Avatar onClick={() => openSelector(true)}>
<Icon>calendar_month</Icon>
</Avatar>
</div>
<DateDisplay onClick={() => openSelector(true)} value={dates().end} isEnd />
</div>
}

export default Dates
39 changes: 22 additions & 17 deletions src/components/DeviceStatistics.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
import { createResource } from 'solid-js'
import type { VoidComponent } from 'solid-js'
import clsx from 'clsx'

import { getDeviceStats } from '~/api/devices'
import { formatDistance, formatDuration } from '~/utils/date'
import { Device } from '~/types'
import Icon from './material/Icon'

type DeviceStatisticsProps = {
class?: string
dongleId: string
device: Device | undefined
}

const DeviceStatistics: VoidComponent<DeviceStatisticsProps> = (props) => {
const [statistics] = createResource(() => props.dongleId, getDeviceStats)
const [statistics] = createResource(() => props.device?.dongle_id, getDeviceStats)
const allTime = () => statistics()?.all

return (
<div class={clsx('flex h-10 w-full gap-8', props.class)}>
<div class="flex flex-col justify-between">
<span class="text-body-sm text-on-surface-variant">Distance</span>
<span class="font-mono text-label-lg uppercase">{formatDistance(allTime()?.distance)}</span>
</div>

<div class="flex flex-col justify-between">
<span class="text-body-sm text-on-surface-variant">Duration</span>
<span class="font-mono text-label-lg uppercase">{formatDuration(allTime()?.minutes)}</span>
type StatProps = {
icon: string
data: string
label: string
}
const Stat: VoidComponent<StatProps> = (props) => {
return <div class="flex basis-1/3 flex-col items-center justify-center">
<div class="flex">
<Icon class="text-on-secondary-container">{`${props.icon}`}</Icon>
<h1>{props.data}</h1>
</div>
<p class="text-sm text-on-secondary-container">{props.label}</p>
</div>
}

<div class="flex flex-col justify-between">
<span class="text-body-sm text-on-surface-variant">Routes</span>
<span class="font-mono text-label-lg uppercase">{allTime()?.routes ?? 0}</span>
</div>
return (
<div class={clsx('flex items-center justify-center p-4', props.class)}>
<Stat icon="distance" label="driven" data={`${Math.round(formatDistance(allTime()?.distance))} mi`} />
<Stat icon="timer" label="duration" data={formatDuration(allTime()?.minutes)} />
<Stat icon="map" label="routes" data={`${allTime()?.routes ?? 0}`} />
</div>
)
}
Expand Down
13 changes: 13 additions & 0 deletions src/components/Loader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { VoidComponent } from 'solid-js'

const Loader: VoidComponent = () => {
return <div role="status">
<svg aria-hidden="true" class="inline size-8 animate-spin fill-on-secondary-container text-transparent" viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/>
<path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill"/>
</svg>
<span class="sr-only">Loading...</span>
</div>
}

export default Loader
15 changes: 15 additions & 0 deletions src/components/Modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { createEffect, createSignal, type ParentComponent } from 'solid-js'

type Props = {
visible: boolean;
}

const Modal:ParentComponent<Props> = (props) => {
const [visible, setVisible] = createSignal(false)
createEffect(() => {
setVisible(props.visible)
})
return <div class={`fixed inset-0 z-40 flex items-center justify-center ${visible() ? '' : 'hidden'} h-screen w-screen bg-neutral-900 opacity-70`}>{props.children}</div>
}

export default Modal
23 changes: 23 additions & 0 deletions src/components/PlaceHolder.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Show, VoidComponent, useContext } from 'solid-js'
import { DashboardContext, generateContextType } from '~/pages/dashboard/Dashboard'

const PlaceHolder: VoidComponent = () => {

const { isDesktop } = useContext(DashboardContext) ?? generateContextType()

return <Show when={isDesktop()}>
<div class="flex size-full flex-col items-center justify-center">
<img
src="/images/logo-connect-placeholder.svg"
alt="comma connect"
width={200}
height={200}
/>
<h1 class="text-2xl font-bold text-secondary-container">connect</h1>
<p class="text-secondary-container">v0.1</p>
<h2 class="text-xl text-secondary-container">select a drive to view</h2>
</div>
</Show>
}

export default PlaceHolder
Loading