Skip to content

Commit

Permalink
fix: show device type name if no alias set (commaai#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
incognitojam authored Jun 13, 2024
1 parent 4aa26ed commit f33774c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/pages/dashboard/activities/DeviceActivity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import { getDevice } from '~/api/devices'
import IconButton from '~/components/material/IconButton'
import TopAppBar from '~/components/material/TopAppBar'
import Typography from '~/components/material/Typography'
import DeviceStatistics from '~/components/DeviceStatistics'
import { getDeviceName } from '~/utils/device'

import RouteList from '../components/RouteList'
import { DashboardContext } from '../Dashboard'
import DeviceStatistics from '~/components/DeviceStatistics'

type DeviceActivityProps = {
dongleId: string
Expand All @@ -18,10 +20,11 @@ const DeviceActivity: VoidComponent<DeviceActivityProps> = (props) => {
const { toggleDrawer } = useContext(DashboardContext)!

const [device] = createResource(() => props.dongleId, getDevice)
const [deviceName] = createResource(device, getDeviceName)
return (
<>
<TopAppBar leading={<IconButton onClick={toggleDrawer}>menu</IconButton>}>
<Suspense fallback={<></>}>{device()?.alias}</Suspense>
{deviceName()}
</TopAppBar>
<div class="flex flex-col gap-4 px-4 pb-4">
<div class="h-[72px] overflow-hidden rounded-lg bg-surface-container-low">
Expand Down
7 changes: 4 additions & 3 deletions src/pages/dashboard/components/DeviceList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import type { VoidComponent } from 'solid-js'
import { useLocation } from '@solidjs/router'
import clsx from 'clsx'

import type { Device } from '~/types'

import Icon from '~/components/material/Icon'
import List, { ListItem, ListItemContent } from '~/components/material/List'
import Typography from '~/components/material/Typography'
import type { Device } from '~/types'
import { getDeviceName } from '~/utils/device'

import { DashboardContext } from '../Dashboard'

type DeviceListProps = {
Expand All @@ -34,7 +35,7 @@ const DeviceList: VoidComponent<DeviceListProps> = (props) => {
href={`/${device.dongle_id}`}
>
<ListItemContent
headline={device.alias}
headline={getDeviceName(device)}
subhead={
<Typography class="lowercase" variant="label-sm">
{device.dongle_id}
Expand Down
6 changes: 6 additions & 0 deletions src/utils/device.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { Device } from '~/types'

export function getDeviceName(device: Device) {
if (device.alias) return device.alias
return `comma ${device.device_type}`
}

0 comments on commit f33774c

Please sign in to comment.